//what the devil is a nodeHandle?
        public override Mesh BuildMeshFromNodeHandle(uint nodeHandle)
        {
            Debug.Log("Trying to build ColoredCubes mesh from node");

            // Create rendering and possible collision meshes.
            Mesh collisionMesh = new Mesh();

            collisionMesh.hideFlags = HideFlags.DontSave;

            // Get the data from Cubiquity.
            int[] indices = CubiquityDLL.GetIndices(nodeHandle);
            ColoredCubesVertex[] cubiquityVertices = CubiquityDLL.GetVertices(nodeHandle);

            // Create the arrays which we'll copy the data to.
            Vector3[] vertices = new Vector3[cubiquityVertices.Length];

            for (int ct = 0; ct < cubiquityVertices.Length; ct++)
            {
                // Get the vertex data from Cubiquity.
                vertices[ct] = new Vector3(cubiquityVertices[ct].x, cubiquityVertices[ct].y, cubiquityVertices[ct].z);
            }

            //FIXME - set collision mesh bounds as we do with rendering mesh?
            collisionMesh.vertices  = vertices;
            collisionMesh.triangles = indices;

            Debug.Log("Collision Mesh Built from verticies of length: " + cubiquityVertices.Length.ToString());

            return(collisionMesh);
        }
        public override Mesh BuildMeshFromNodeHandle(uint nodeHandle)
        {
            // At some point I should read this: http://forum.unity3d.com/threads/5687-C-plugin-pass-arrays-from-C

            // Create rendering and possible collision meshes.
            Mesh collisionMesh = new Mesh();

            collisionMesh.hideFlags = HideFlags.DontSave;

            // Get the data from Cubiquity.
            int[] indices = CubiquityDLL.GetIndices(nodeHandle);
            ColoredCubesVertex[] cubiquityVertices = CubiquityDLL.GetVertices(nodeHandle);

            // Create the arrays which we'll copy the data to.
            Vector3[] vertices = new Vector3[cubiquityVertices.Length];

            for (int ct = 0; ct < cubiquityVertices.Length; ct++)
            {
                // Get the vertex data from Cubiquity.
                vertices[ct] = new Vector3(cubiquityVertices[ct].x, cubiquityVertices[ct].y, cubiquityVertices[ct].z);
            }

            //FIXME - set collision mesh bounds as we do with rendering mesh?
            collisionMesh.vertices  = vertices;
            collisionMesh.triangles = indices;

            return(collisionMesh);
        }
        /// <summary>
        /// Builds the Mesh represented by the Node. Uses the Node's nodeHandle (inherited from OctreeNodeAlt)
        /// </summary>
        /// <returns>The mesh.</returns>
        public override Mesh BuildMesh()
        {
            // At some point I should read this: http://forum.unity3d.com/threads/5687-C-plugin-pass-arrays-from-C

            Vector3 offset = new Vector3(0.5f, 0.5f, 0.5f);             // Required for the CubicVertex decoding process.

            // Meshes for rendering and collition.
            Mesh mesh = new Mesh();

            //prevents memory leaks >:)
            mesh.hideFlags = HideFlags.DontSave;

            // Get the data from where it is stored in Cubiquity.
            int[] indices = CubiquityDLL.GetIndices(nodeHandle);
            ColoredCubesVertex[] cubiquityVertices = CubiquityDLL.GetVertices(nodeHandle);

            // Create the arrays which we'll copy the data to.
            Vector3[] rendererVertices = new Vector3[cubiquityVertices.Length];
            Color32[] rendererColors   = new Color32[cubiquityVertices.Length];

            //translate the data from Cubiquity's forms to Unity's
            for (int ct = 0; ct < cubiquityVertices.Length; ct++)
            {
                // Get the vertex data from Cubiquity.
                Vector3 position = new Vector3(cubiquityVertices[ct].x, cubiquityVertices[ct].y, cubiquityVertices[ct].z);

                // Part of the CubicVertex decoding process.
                position -= offset;

                //nab the color
                QuantizedColor color = cubiquityVertices[ct].color;

                // Copy it to the arrays.
                rendererVertices[ct] = position;
                rendererColors[ct]   = (Color32)color;
            }

            // Assign vertex data to the meshes.
            mesh.vertices  = rendererVertices;
            mesh.colors32  = rendererColors;
            mesh.triangles = indices;

            // FIXME - Get proper bounds
            mesh.bounds.SetMinMax(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(32.0f, 32.0f, 32.0f));
            mesh.name = "nodeHandle: " + nodeHandle.ToString();

            return(mesh);
            //return null;
        }
示例#4
0
            public Mesh BuildMeshFromNodeHandleForColoredCubesVolume(uint nodeHandle)
            {
                // At some point I should read this: http://forum.unity3d.com/threads/5687-C-plugin-pass-arrays-from-C

                Vector3 offset = new Vector3(0.5f, 0.5f, 0.5f);                 // Required for the CubicVertex decoding process.

                // Create rendering and possible collision meshes.
                Mesh renderingMesh = new Mesh();

                renderingMesh.hideFlags = HideFlags.DontSave;

                // Get the data from Cubiquity.
                int[] indices = CubiquityDLL.GetIndices(nodeHandle);
                ColoredCubesVertex[] cubiquityVertices = CubiquityDLL.GetVertices(nodeHandle);

                // Create the arrays which we'll copy the data to.
                Vector3[] renderingVertices = new Vector3[cubiquityVertices.Length];
                Color32[] renderingColors   = new Color32[cubiquityVertices.Length];

                for (int ct = 0; ct < cubiquityVertices.Length; ct++)
                {
                    // Get the vertex data from Cubiquity.
                    Vector3 position = new Vector3(cubiquityVertices[ct].x, cubiquityVertices[ct].y, cubiquityVertices[ct].z);
                    position -= offset;                     // Part of the CubicVertex decoding process.
                    QuantizedColor color = cubiquityVertices[ct].color;

                    // Copy it to the arrays.
                    renderingVertices[ct] = position;
                    renderingColors[ct]   = (Color32)color;
                }

                // Assign vertex data to the meshes.
                renderingMesh.vertices  = renderingVertices;
                renderingMesh.colors32  = renderingColors;
                renderingMesh.triangles = indices;

                // FIXME - Get proper bounds
                renderingMesh.bounds.SetMinMax(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(32.0f, 32.0f, 32.0f));

                return(renderingMesh);
            }