diff --git a/Assets/Materials/Mat_PointCloud.mat b/Assets/Materials/Mat_PointCloud.mat index f326dc423ea1c012c31bab12bc0adf04a1f9acf7..508fc1344aaf155fee6624c520c99f0052e151a2 100644 --- a/Assets/Materials/Mat_PointCloud.mat +++ b/Assets/Materials/Mat_PointCloud.mat @@ -117,7 +117,7 @@ Material: - _GlossyReflections: 1 - _Metallic: 0 - _OcclusionStrength: 1 - - _Opacity: 1 + - _Opacity: 0.5 - _Parallax: 0.02 - _QueueControl: 0 - _QueueOffset: 0 diff --git a/Assets/Scrips/Controllers/SelectPointsController.cs b/Assets/Scrips/Controllers/SelectPointsController.cs index 5b8c06899399ddbd2e11c09dc9c4b484d5685b69..7870923601f1a5b6402a19a9ab0036ddf202bb30 100644 --- a/Assets/Scrips/Controllers/SelectPointsController.cs +++ b/Assets/Scrips/Controllers/SelectPointsController.cs @@ -27,7 +27,7 @@ public class SelectPointsController : MonoBehaviour private List<Vector3> _recalculatedPoints; - private void Awake() + public void Awake() { if (Instance != null && Instance != this) { @@ -71,21 +71,14 @@ public class SelectPointsController : MonoBehaviour List<Vector3> selectedPoints = new(); for (int i1 = 0; i1 < cloudPoints.Count; i1++) { - // GameObject cloud = pointClouds[i1]; - // Transform cloudTransform = cloud.transform; - // Point[] points = cloud.GetComponent<PointCloudDataReader>().PointData; Point[] points = cloudPoints[i1]; for (int i = 0; i < points.Length; i++) { Vector3 point = points[i].position; point.x *= -1f; - // foreach (GameObject blockSelection in _blockSelections) foreach (Bounds bound in selectionBounds) { - // MeshCollider collider = blockSelection.GetComponent<MeshCollider>(); - // Vector3 ptGlobal = cloudTransform.rotation * point + cloudTransform.position; Vector3 ptGlobal = cloudRotations[i1] * point + cloudPositions[i1]; - // if (collider.bounds.Contains(ptGlobal)) if (bound.Contains(ptGlobal)) { selectedPoints.Add(ptGlobal); @@ -141,7 +134,6 @@ public class SelectPointsController : MonoBehaviour Vector<float> planeEq = vt.Row(3); Vector3 planeNormal = new(planeEq[0], planeEq[1], planeEq[2]); - // planeNormal = pointClouds[0].transform.rotation * planeNormal; planeNormal.Normalize(); float d = planeNormal.x * points[0].x + planeNormal.y * points[0].y + planeNormal.z * points[0].z; @@ -193,15 +185,6 @@ public class SelectPointsController : MonoBehaviour return projectedPoint; } - // private void OnDrawGizmosSelected() - // { - // Gizmos.color = Color.red; - // foreach (Vector3 pt in _debugPoints) - // { - // Gizmos.DrawSphere(pt, 0.05f); - // } - // } - public void AddSelection(GameObject selection) { _blockSelections.Add(selection); @@ -222,22 +205,6 @@ public class SelectPointsController : MonoBehaviour Destroy(selection); } - // Start is called before the first frame update - void Start() - { - // CalculateRealPoints(); - EditState.Instance.RegisterListener(EditChangeHandler); - // SpawnPlane(new Vector3(0, 0, 0), Vector3.left); - // SpawnPlane(new Vector3(-1, 0, 0), Vector3.up); - } - - private void EditChangeHandler() - { - // if (EditState.Instance.ActiveEditState != EditState.EditType.Select) - // { - // ClearSelection(); - // } - } public void SetOpacity(float opacity) { diff --git a/Assets/Shaders/DeformTextureGraph.shadergraph b/Assets/Shaders/DeformTextureGraph.shadergraph index 79f157c9d6adf324007caf74469d2434d1c19f4e..0991b789c6dfbcae115537a238e6b73236b010a3 100644 --- a/Assets/Shaders/DeformTextureGraph.shadergraph +++ b/Assets/Shaders/DeformTextureGraph.shadergraph @@ -139,8 +139,8 @@ }, "m_FragmentContext": { "m_Position": { - "x": 0.000015735626220703125, - "y": 342.0 + "x": -2.000033378601074, + "y": 345.0000305175781 }, "m_Blocks": [ { @@ -311,10 +311,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -452.0000305175781, - "y": 287.0, - "width": 105.0, - "height": 34.000030517578128 + "x": -320.0000305175781, + "y": 208.0, + "width": 104.99998474121094, + "height": 34.0 } }, "m_Slots": [ @@ -395,9 +395,9 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -326.0, - "y": 321.0, - "width": 130.00001525878907, + "x": -200.00003051757813, + "y": 262.0, + "width": 130.00003051757813, "height": 118.0 } }, @@ -662,8 +662,8 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -730.0, - "y": 380.0, + "x": -589.0, + "y": 277.0000305175781, "width": 139.0, "height": 34.0 } @@ -954,10 +954,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -543.0000610351563, - "y": 342.0, - "width": 183.00003051757813, - "height": 251.0 + "x": -433.0000305175781, + "y": 286.0000305175781, + "width": 183.00001525878907, + "height": 251.00003051757813 } }, "m_Slots": [ diff --git a/Assets/mesh.obj b/Assets/mesh.obj index a2ebe60679596f77fe4c5caae7c7b99226258243..f2038a5d923081ea0179490ab8335609efdc1a1b 100644 --- a/Assets/mesh.obj +++ b/Assets/mesh.obj @@ -1,27 +1,27 @@ -v 4.790933 0.0005001426 3.249483 -v 4.190578 0.0005001426 3.249483 -v 4.790933 5.129273 3.249483 -v 4.190578 5.129273 3.249483 -v 4.790933 5.129273 2.379545 -v 4.190578 5.129273 2.379545 -v 4.790933 0.0005001426 2.379545 -v 4.190578 0.0005001426 2.379545 -v 4.790933 5.129273 3.249483 -v 4.190578 5.129273 3.249483 -v 4.790933 5.129273 2.379545 -v 4.190578 5.129273 2.379545 -v 4.790933 0.0005001426 2.379545 -v 4.790933 0.0005001426 3.249483 -v 4.190578 0.0005001426 3.249483 -v 4.190578 0.0005001426 2.379545 -v 4.190578 0.0005001426 3.249483 -v 4.190578 5.129273 3.249483 -v 4.190578 5.129273 2.379545 -v 4.190578 0.0005001426 2.379545 -v 4.790933 0.0005001426 2.379545 -v 4.790933 5.129273 2.379545 -v 4.790933 5.129273 3.249483 -v 4.790933 0.0005001426 3.249483 +v 4.83444 0.0005001426 3.147868 +v 4.159263 0.0005001426 3.147868 +v 4.83444 2.654525 3.147868 +v 4.159263 2.654525 3.147868 +v 4.83444 2.654525 2.391667 +v 4.159263 2.654525 2.391667 +v 4.83444 0.0005001426 2.391667 +v 4.159263 0.0005001426 2.391667 +v 4.83444 2.654525 3.147868 +v 4.159263 2.654525 3.147868 +v 4.83444 2.654525 2.391667 +v 4.159263 2.654525 2.391667 +v 4.83444 0.0005001426 2.391667 +v 4.83444 0.0005001426 3.147868 +v 4.159263 0.0005001426 3.147868 +v 4.159263 0.0005001426 2.391667 +v 4.159263 0.0005001426 3.147868 +v 4.159263 2.654525 3.147868 +v 4.159263 2.654525 2.391667 +v 4.159263 0.0005001426 2.391667 +v 4.83444 0.0005001426 2.391667 +v 4.83444 2.654525 2.391667 +v 4.83444 2.654525 3.147868 +v 4.83444 0.0005001426 3.147868 f 1 3 4 f 1 4 2 f 9 5 6 @@ -34,9 +34,9 @@ f 17 18 19 f 17 19 20 f 21 22 23 f 21 23 24 -v 5.100156 -0.02601445 14.33806 -v 7.014131 0.03212595 14.30453 -v 5.094431 2.09043 14.34149 -v 6.875519 2.140711 14.31028 +v -4.236339 0.1598767 4.518488 +v -4.025891 -0.008035362 5.832972 +v -4.22403 1.725446 4.65662 +v -4.025449 1.80238 5.906134 f 25 28 26 f 28 25 27 diff --git a/README.md b/README.md index 48b5dc01ff840c4971a736cf0ed8fc2b1cbf105c..0321bf1fac4a3e5bc70780969fa23d7d486225a2 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,11 @@ -# onlab +# Szakdolgozat +3D modellező program VR-ban pontfelhő rekonstrukciós feladatok segítésére. +## Setup -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://dev.itk.ppke.hu/vr/onlab.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://dev.itk.ppke.hu/vr/onlab/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +- [ ] 2022.3.19f Unity Editor kell a futtatáshoz +- [ ] Projektet add hozzá a Unity Hub-hoz +- [ ] Meta Quest Link-et kapcsold be +- [ ] Build Settings-ben Android platform-ra válts át, majd a szemüveget válaszd ki +- [ ] Quest Link használata közben az Editorban nyomd meg a Play gombot diff --git a/TETRA.txt b/TETRA.txt deleted file mode 100644 index 3c60911a7c9438175f2717d71479b1d418675077..0000000000000000000000000000000000000000 --- a/TETRA.txt +++ /dev/null @@ -1,720 +0,0 @@ --- Left thumbstick: move and strafe --- Right thumbstick: rotate the view horizontally - --- Right grip: switch to snap locomotion mode --- Left grip: enable flying mode --- Left trigger: switch orientation to left hand controller (can look around while moving) - -local socket = require 'socket' - -local TEST = false -local SAVE_TO_FILE = false - -function customTablePrint(t) - for k,v in pairs(t) do - print(k,v) - if type(v)=="table" then - customTablePrint(v) - end - end -end - - -function getTime() - return socket.gettime() * 1000 -- to ms -end - -local last_data = nil - -function udp_init() - --local s_address, s_port = "10.3.18.178", 55555 - local s_address, s_port = "0.0.0.0", 5555 - udp = socket.udp() - assert(udp:settimeout(0)) - --assert(udp:settimeout(1e-10)) - assert(udp:setsockname(s_address, s_port)) -end - -function udp_update() - act_data = udp:receive(12000) -- string data - - if TEST then - act_data = "" - local pts = math.random(300,800) - local range = 2 - local step = range*2/(pts-0.5) - local tmp = 0 - for deg = -range, range, step do - local z = math.random(1000,5000) -- mm - act_data = act_data .. deg .. ' ' .. z .. '\n' - tmp = tmp + 1 - end - print('udp new pts', tmp) - end --- print(act_data) - - if act_data then - last_data = act_data - - if SAVE_TO_FILE then - local filename = "./udp.txt" - file = io.open (filename, "a") - io.output(file) - io.write("TS_" .. getTime() .. "\n") - io.write(act_data) - io.close(file) - end - end - ---[[ - if act_data then - print(string.len(act_data)) - else - --print(act_data) - end ---]] - - return last_data -end - - -Cloud = {} -CloudMeta = {__index = Cloud} - -function Cloud:new(mode, staticness, scanMode) - local obj = { - mesh = nil, - vertices = {}, - mode = mode, -- "points", "lines", "triangles", - staticness = staticness, -- "static", "dynamic", - trisize = 0.01, - scanCounter = 0, - scanMode = scanMode, - shader = nil, - maxPointsPerScan = 1000, -- Upper bound - maxScansToStore = -1, - verticesPerPoint = 1, - current_buffer_index = 1, - file_write = 0, - color_rule = 0, - pcfile = io.open("pointcloud.xyz","w"), - } - - if mode == "lines" then - obj.verticesPerPoint = 12 - end - if mode == "triangles" then - obj.verticesPerPoint = 12 - end - --- if obj.mode == "triangles" then - -- table.insert(obj.vertices, {0,0,0}) --very strange stuff, why do I need this? - -- end - return setmetatable(obj, CloudMeta) -end - -function Cloud.meshShaderForScan() - meshFormat = { { 'vPosition', 'float', 3 }, { 'scanCounter', 'int', 1 },{'vNorm','float',3} } - meshShader = lovr.graphics.newShader([[ - const float LIFETIME_MS = 10000; - in vec3 vPosition; - in vec3 vNorm; - in int scanCounter; - uniform int currentScanCounter; - flat out int vScanCounter; - flat out vec3 vPos2; - vec4 position(mat4 projection, mat4 transform, vec4 vertex) - { - float diff = currentScanCounter - scanCounter; - if (diff > LIFETIME_MS) - return projection * transform * vec4(0.0,0.0,0.0,0.0); - vScanCounter = scanCounter; - vPos2 = vNorm; - return projection * transform * vec4(vPosition, 1.0); - } - ]], - [[ - const float COLORTIME_MS = 10000; - flat in int vScanCounter; - flat in vec3 vPos2; - in vec3 vNorm; - uniform int currentScanCounter; - vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) - { - float diff = currentScanCounter - vScanCounter; - float intensity = diff > COLORTIME_MS ? 0 : 1. - sqrt(diff / COLORTIME_MS); - return vec4(intensity * vec3(fract(vPos2.x),fract(vPos2.y),fract(vPos2.z)), 1.0); - } - ]]) - - return meshFormat, meshShader -end - -function Cloud.meshShaderForShip() - meshFormat = { { 'vPosition', 'float', 3 }, { 'shipColor', 'float', 3 } } - meshShader = lovr.graphics.newShader([[ - in vec3 vPosition; - in vec3 shipColor; - out vec3 shipColorOut; - vec4 position(mat4 projection, mat4 transform, vec4 vertex) - { - shipColorOut = shipColor; - return projection * transform * vec4(vPosition,1.0); - } - ]], - [[ - in vec3 shipColorOut; - vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) - { - return vec4(shipColorOut, 1.0); - //return vec4(1.0,0.0,1.0,1.0); - } - ]]) - - return meshFormat, meshShader -end - -function Cloud:addLineInner(pointFrom, pointTo, additional) - self:addPointInner(pointFrom, additional) - self:addPointInner(pointTo, additional) -end - -function Cloud:addTriangleInner(point1, point2, point3,additional) - self:addPointInner(point1, additional) - self:addPointInner(point2, additional) - self:addPointInner(point3, additional) -end - -function Cloud:addPointInner(point, additional) - if additional ~= nil then - for _,v in ipairs(additional) do - table.insert(point,v) - end - end - --- x=point[1] --- y=point[2] --- z=point[3] --- if x==nil or y == nil or z == nil then --- print("NIL FOUND") --- end - - table.insert(self.vertices, point) -end - -function Cloud:calculateTetrahedron(x,y,z) - A = { x, y, z+2*self.trisize/3 } - B = {x + self.trisize* math.cos( 0 / 3 * 2 * math.pi), y + self.trisize* math.sin( 0 / 3 * 2 * math.pi), z-self.trisize/3} - C = {x + self.trisize* math.cos( 1 / 3 * 2 * math.pi), y + self.trisize* math.sin( 1 / 3 * 2 * math.pi), z-self.trisize/3} - D = {x + self.trisize* math.cos( 2 / 3 * 2 * math.pi), y + self.trisize* math.sin( 2 / 3 * 2 * math.pi), z-self.trisize/3} - --[[ - print("--------------------------------------------------") - print(x,y,z) - customTablePrint(A) - customTablePrint(B) - customTablePrint(C) - customTablePrint(D) - --]] - return A,B,C,D -end ---[[ -function Cloud:calculateLinesABCD(x,y,z) - A = { x, y, z+2*self.trisize/3 } - B = {x + self.trisize* math.cos( 0 / 3 * 2 * math.pi), y + self.trisize* math.sin( 0 / 3 * 2 * math.pi), z-self.trisize/3} - C = {x + self.trisize* math.cos( 1 / 3 * 2 * math.pi), y + self.trisize* math.sin( 1 / 3 * 2 * math.pi), z-self.trisize/3} - D = {x + self.trisize* math.cos( 2 / 3 * 2 * math.pi), y + self.trisize* math.sin( 2 / 3 * 2 * math.pi), z-self.trisize/3} - return A,B,C,D -end ---]] - -function Cloud:addPointXYZ(x,y,z, additional) - if self.mode == "points" then - self:addPointInner({x,y,z}, additional) - end - if self.mode == "triangles" then - A,B,C,D = self:calculateTetrahedron(x,y,z) - - self:addTriangleInner(A,B,C, additional) - self:addTriangleInner(A,B,D, additional) - self:addTriangleInner(A,D,B, additional) - self:addTriangleInner(B,C,D, additional) - end - if self.mode == "lines" then - A,B,C,D = self:calculateTetrahedron(x,y,z) - - self:addLineInner(A,B, additional) - self:addLineInner(A,C, additional) - self:addLineInner(A,D, additional) - - self:addLineInner(C,B, additional) - self:addLineInner(D,C, additional) - self:addLineInner(B,D, additional) - end -end - -function Cloud:draw() - if self.shader ~= nil then - if self.scanMode then --- self.shader:send("currentScanCounter", self.scanCounter) - self.shader:send("currentScanCounter", getTime()) - end - - lovr.graphics.setShader(self.shader) - end - - self.mesh:draw() - lovr.graphics.setShader() -end - -function Cloud:createMesh(meshFormat, meshShader) - if meshFormat == nil then - self.mesh = lovr.graphics.newMesh(self.vertices, self.mode,self.staticness, false) - else - self.mesh = lovr.graphics.newMesh(meshFormat, self.vertices, self.mode,self.staticness, true) - end - - self.shader = meshShader - self.vertices = {} -end - -function Cloud:getMaxVerticiesBufferSize() - return self.maxScansToStore * self.maxPointsPerScan * self.verticesPerPoint -end -function Cloud:setAllZeroAllVerticesInSelf() - size = self:getMaxVerticiesBufferSize() - self.vertices = {} - for index = 1, size do - table.insert(self.vertices, {0, 0, 0, 0}) - end -end -function Cloud:prepare(maxScansToStore, meshFormat, meshShader) - self.maxScansToStore = maxScansToStore - self:setAllZeroAllVerticesInSelf() - self:createMesh(meshFormat, meshShader) -end - -function Cloud:update(newMeasuredPoints) --- meshVerticesIndex = self.scanCounter % self.maxScansToStore --- self.scanCounter = self.scanCounter + 1 - - for _,v in ipairs(newMeasuredPoints) do - self:addPointXYZ(v[1],v[2],v[3], {getTime(), v[4],v[5],v[6]}); - if (self.file_write==1) then - self.pcfile:write(string.format("%.4f %.4f %.4f",v[1],v[2],v[3])," ", math.floor(v[4]*255)," ",math.floor(v[5]*255)," ",math.floor(v[6]*255),"\n") - end - end - - local max_verticies_buffer_size = self:getMaxVerticiesBufferSize() - - if #self.vertices > max_verticies_buffer_size then - print("ERROR - TOO SMALL VERTEX BUFFER") -- ERROR - ERROR() -- exception? XD -- fixme - end - - local spaceInBuffer = math.min(#self.vertices, max_verticies_buffer_size-self.current_buffer_index+1) - if spaceInBuffer > 0 then - scan.mesh:setVertices(self.vertices, self.current_buffer_index, spaceInBuffer) - end - if spaceInBuffer ~= #self.vertices then - self.current_buffer_index = 1 -- reset (circular) - spaceInBuffer = #self.vertices - spaceInBuffer -- the leftover - -- build rest of the vertices - - -- Speedup? - local leftover = {} - for idx = spaceInBuffer+1, #self.vertices do - table.insert(leftover, self.vertices[idx]) - end - spaceInBuffer = #leftover - scan.mesh:setVertices( leftover, self.current_buffer_index, spaceInBuffer) - --- scan.mesh:setVertices( { unpack(self.vertices, spaceInBuffer+1) }, self.current_buffer_index, spaceInBuffer) -- sometimes crashes with too large unpack size... ??? - end - self.current_buffer_index = self.current_buffer_index + spaceInBuffer - - self.vertices = {} -end - -function Cloud:reset() - self:setAllZeroAllVerticesInSelf() - scan.mesh:setVertices(self.vertices, idx) - self.vertices = {} - self.scanCounter = 0 - print('Scans are reseted') -end - -local motion = { - pose = lovr.math.newMat4(), -- Transformation in VR initialized to origin (0,0,0) looking down -Z - thumbstickDeadzone = 0.4, -- Smaller thumbstick displacements are ignored (too much noise) - directionFrom = 'head', -- Movement can be relative to orientation of head or left controller - flying = false, - -- Snap motion parameters - snapTurnAngle = 2 * math.pi / 12, - dashDistance = 1.5, - thumbstickCooldownTime = 0.3, - thumbstickCooldown = 0, - -- Smooth motion parameters - turningSpeed = 2 * math.pi * 1 / 6, - walkingSpeed = 4, - last_direction_x = 0, - last_direction_y = 0, - last_direction_z = 0, - maxWalkingSpeed = 2, - drawing = false, - -- drawsize = 2000000, --- currentdrawindex = 0, - environment_behavior = 0, -} - - -function motion.smooth(dt) - if lovr.headset.isTracked('right') then - local x, y = lovr.headset.getAxis('right', 'touchpad') - -- Smooth horizontal turning - if math.abs(x) > motion.thumbstickDeadzone then - motion.pose:rotate(-x * motion.turningSpeed * dt, 0, 1, 0) - end - end - if lovr.headset.isTracked('left') then - local x, y = lovr.headset.getAxis('left', 'touchpad') - local direction = quat(lovr.headset.getOrientation(motion.directionFrom)):direction() - - if motion.directionFrom == 'left' then - direction = quat(-math.pi / 4, 1,0,0):mul(vec3(direction)) - end - if not motion.flying then - direction.y = 0 - end - last_direction = lovr.math.newVec3(0, 0, 0) - -- Smooth strafe movement - if math.abs(x) > motion.thumbstickDeadzone then - local strafeVector = quat(-math.pi / 2, 0,1,0):mul(vec3(direction)) - last_direction = last_direction + (strafeVector * x * motion.maxWalkingSpeed * dt) --- motion.pose:translate(strafeVector * x * motion.walkingSpeed * dt) - end - -- Smooth Forward/backward movement - if math.abs(y) > motion.thumbstickDeadzone then - --- motion.pose:translate(direction * y * motion.walkingSpeed * dt) - last_direction = last_direction + (direction * y * motion.maxWalkingSpeed * dt) - end - motion.last_direction_x = motion.last_direction_x + last_direction.x - motion.last_direction_y = motion.last_direction_y + last_direction.y - motion.last_direction_z = motion.last_direction_z + last_direction.z - motion.pose:translate(motion.last_direction_x,motion.last_direction_y,motion.last_direction_z) - motion.last_direction_x = motion.last_direction_x * .9 - motion.last_direction_y = motion.last_direction_y * .9 - motion.last_direction_z = motion.last_direction_z * .9 - end -end - -function motion.snap(dt) - -- Snap horizontal turning - if lovr.headset.isTracked('right') then - local x, y = lovr.headset.getAxis('right', 'touchpad') - if math.abs(x) > motion.thumbstickDeadzone and motion.thumbstickCooldown < 0 then - local angle = -x / math.abs(x) * motion.snapTurnAngle - motion.pose:rotate(angle, 0, 1, 0) - motion.thumbstickCooldown = motion.thumbstickCooldownTime - end - end - -- Dashing forward/backward - if lovr.headset.isTracked('left') then - local x, y = lovr.headset.getAxis('left', 'touchpad') - if math.abs(y) > motion.thumbstickDeadzone and motion.thumbstickCooldown < 0 then - local moveVector = quat(lovr.headset.getOrientation('head')):direction() - if not motion.flying then - moveVector.y = 0 - end - moveVector:mul(y / math.abs(y) * motion.dashDistance) - motion.pose:translate(moveVector) - motion.thumbstickCooldown = motion.thumbstickCooldownTime - end - end - motion.thumbstickCooldown = motion.thumbstickCooldown - dt -end - - -function motion_with_rotation() - local isTracked = lovr.headset.isTracked() - if lastHP and isTracked then - local actPos = vec3(actHP) - local lastPos = vec3(lastHP) - motion.pose:translate(lastPos - actPos) - end - if isTracked then - lastHP = lovr.math.newMat4(actHP) - end -end -function motion_as_static_env() - local isTracked = lovr.headset.isTracked() - if lastHP and isTracked then - motion.pose:mul(mat4(lastHP):mul(mat4(actHP):invert())) --- print(motion.pose:unpack()) - end - if isTracked then - lastHP = lovr.math.newMat4(actHP) - end -end - -local HUD = { - DISPLAY_FRAME_NUM = 200, - display_string = nill, - live = -1, -} -function lovr.update(dt) - data = udp_update() - --print("UPDATE") - --[[ - if data then - print(string.len(data)) - else - print(data) - end - --]] - - ------------------- ENV BEHAVIOR ------------------- - if lovr.headset.wasReleased('right', 'grip') then - motion.environment_behavior = motion.environment_behavior + 1 - if motion.environment_behavior > 2 then - motion.environment_behavior = 0 - lastHP = nil -- reset - end - -- HUD display - HUD.live = HUD.DISPLAY_FRAME_NUM - if motion.environment_behavior == 0 then - HUD.display_string = 'Nomal tracked' - elseif motion.environment_behavior == 1 then - HUD.display_string = 'Just rotation' - elseif motion.environment_behavior == 2 then - HUD.display_string = 'No track' - else - HUD.display_string = 'FIX ME' - end - end - - if lovr.headset.isTracked() then - actHP = lovr.math.newMat4(lovr.headset.getPose()) - end - if motion.environment_behavior == 1 then - motion_with_rotation() - elseif motion.environment_behavior == 2 then - motion_as_static_env() - end - ----------------------------------------------------- - - ---[[ - motion.directionFrom = lovr.headset.isDown('left', 'trigger') and 'left' or 'head' - if lovr.headset.isDown('left', 'grip') then - motion.flying = true - elseif lovr.headset.wasReleased('left', 'grip') then - motion.flying = false - local height = vec3(motion.pose).y - motion.pose:translate(0, -height, 0) - end - - if lovr.headset.isDown('right', 'trigger') then - motion.drawing = true - elseif lovr.headset.wasReleased('right', 'trigger') then - motion.drawing = false - end - - if motion.drawing or TEST then - local handString = 'hand/right' - - if TEST then handString = 'hand/left' end -- hack for test - - local posehand = lovr.math.newMat4(lovr.headset.getPose(handString)) - local globhand = lovr.math.newMat4(motion.pose) - globhand:mul(posehand); - local newpointcount = 0 - - lidardeg={} - lidardist={} - - if data then --- print(string.len(data)) - - for deg, dist in string.gmatch(data, "([%w.e-]+) ([%w.e-]+)\n") do --- table.insert(lidardeg,-deg) --- table.insert(lidardist, -dist/1000) - ----[[ - if tonumber(dist) > 20 then - table.insert(lidardeg,-deg) - table.insert(lidardist, -dist/1000) - - else - table.insert(lidardeg, 0) - table.insert(lidardist, 10000) - end - --if deg == nil or dist == nil then - -- print(deg .. " " .. dist) - -- end - --]] - --print(data) - end - - newpointcount = #lidardeg --- print(newpointcount) - last_data = nil - end - - --print(motion.currentdrawindex) - - local rotation_offset = -math.pi/12 - local translation_offset = vec3(-0.06,-0.1,0) - - newMeasuredPoints = {} - for i=1,newpointcount do - if lidardeg[i] then - local locdir = lovr.math.newMat4(globhand) - locdir:rotate(quat(lidardeg[i]+rotation_offset, 1,0,0)) - locdir:translate(vec3(0,0,lidardist[i]) + translation_offset); - local handx, handy, handz, handsx, handsy, handsz, handr1, handr2, handr3, handr4 = locdir:unpack(); - local normx,normy, normz; - if scan.color_rule > 2 then - scan.color_rule = 0; - end - if scan.color_rule == 0 then - normx=0.99; - normy=0.99; - normz=0.99 ; - end - if (scan.color_rule == 1) then - if i>1 and lidardeg[i-1] then - normx=10*(lidardist[i-1]-lidardist[i]) - normy=0.5+2*(lidardist[i-1]-lidardist[i]) - normz=1.0-10*(lidardist[i-1]-lidardist[i]) - else - normx=0.5; - normy=0.5; - normz=0.5; - end - end - if (scan.color_rule == 2) then - normx=math.fmod(handx,1) - normy=math.fmod(handy,1) - normz=math.fmod(handz,1) - end - table.insert(newMeasuredPoints, {handx,handy,handz, normx, normy, normz}) - --if handx == n --- motion.currentdrawindex = motion.currentdrawindex + newpointcount --- if (motion.currentdrawindex >= motion.drawsize- newpointcount) then --- motion.currentdrawindex = 0 --- end - end - end - scan:update(newMeasuredPoints) - --scan:setVertices(newvertices, origmeshsize + motion.currentdrawindex) - end - - motion.smooth(dt) - --[[ - if lovr.headset.isDown('right', 'grip') then - motion.snap(dt) - else - motion.smooth(dt) - end - --]] - - if SAVE_TO_FILE then - local headPose = lovr.math.newMat4(lovr.headset.getPose('head')) - local handPose = lovr.math.newMat4(lovr.headset.getPose('hand/right')) - local filename = "./track.txt" - file = io.open (filename, "a") - io.output(file) - io.write("TS_" .. getTime() .. "\n") - io.write("HEAD_") - local tmp = { headPose:unpack(true) } - for idx = 1, 16 do - io.write(tmp[idx] .. "|") - end - io.write("\nHAND_") - local tmp = { handPose:unpack(true) } - for idx = 1, 16 do - io.write(tmp[idx] .. "|") - end - io.write("\n") - io.close(file) - end -end - ------------------------------ EVENTS ----------------------------- -function lovr.keyreleased(key, scancode) - if key == 'r' then -- scan reset - scan:reset() - end - if key == 'f' then - scan.file_write = 1-scan.file_write - end - if key == 'c' then - scan.color_rule = scan.color_rule+1; - end -end ------------------------------------------------------------------- - -function lovr.draw() --- lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1) - lovr.graphics.setBackgroundColor(0,0,0) - lovr.graphics.transform(mat4(motion.pose):invert()) - - -- Render hands - lovr.graphics.setColor(1,1,1) - local radius = 0.05 - for _, hand in ipairs(lovr.headset.getHands()) do - -- Whenever pose of hand or head is used, need to account for VR movement - local poseRW = mat4(lovr.headset.getPose(hand)) - local poseVR = mat4(motion.pose):mul(poseRW) - poseVR:scale(radius) - lovr.graphics.box('line',poseVR) - end - - if ship ~= nil and ship.mesh ~= nil then - --ship:draw() - end - if scan ~= nil and scan.mesh ~= nil then - scan:draw() - end - - -- Display HUD - if HUD.live > 0 then - local pose = mat4(motion.pose):mul(mat4(lovr.headset.getPose())) - local textPos = pose:mul(vec3(0,0,-1,1)) - local x,y,z, sx,sy,sz, angle,ax,ay,az = pose:unpack() - lovr.graphics.print(HUD.display_string, textPos[1],textPos[2],textPos[3], .1, angle,ax,ay,az) - HUD.live = HUD.live - 1 - end -end - -function lovr.load() - udp_init() - - --local file = io.open("data/centered.ply") -- sunken "Hableány" ship measured by Norbit. - if file then - ship = Cloud:new("points","static", false) - while true do - local x,z,y,r,g,b=file:read("*n","*n","*n","*n","*n","*n") - if x == nil then break end - - ship:addPointXYZ(x,y,z, {r/255,g/255,b/255}) - end - ship:createMesh(Cloud.meshShaderForShip()) - else - print("open error") - end - --- scan = Cloud:new("points", "dynamic", true) - scan = Cloud:new("lines", "dynamic", true) --- scan = Cloud:new("triangles", "dynamic", true) - scan:prepare(50, Cloud.meshShaderForScan()) - - print(scan.verticesPerPoint) - - --customTablePrint(ship:getVertexFormat()) -end - - - - -