Ejemplo n.º 1
0
        /// <summary>
        /// Applies a brush to the terrain.
        /// </summary>
        /// <param name="type">The type/shape of the brush.</param>
        /// <param name="size">The size (radius) of the brush.</param>
        /// <param name="pos">The (real world) position to apply the brush.</param>
        /// <param name="val">Density to apply.</param>
        public static void applyBrush(BrushType type, int size, Vector3 pos, float val)
        {
            List<Node> changedNodes = new List<Node>();
            float nodeWidth = NodeManager.LODSize[0];
            Vector3 realPos = new Vector3();
            Vector3I point = new Vector3I((int)Math.Round(pos.x / nodeWidth),
                (int)Math.Round(pos.y / nodeWidth),
                (int)Math.Round(pos.z / nodeWidth));

            List<Vector3> points = getPoints(type, size, pos);
            for (int o = 0; o < points.Count; o++)
            {
                realPos = points[o];
                Node[] editNodes = NodeManager.searchNodeContainingDensity(realPos, 0);

                for (int i = 0; i < editNodes.Length; i++)
                {
                    Node editNode = editNodes[i];
                    if (editNode != null && editNode.LOD == 0)
                    {
                        if (!changedNodes.Contains(editNode))
                            changedNodes.Add(editNode);

                        if (type == BrushType.SPHERE)
                        {
                            float v = val;
                            float dist = Vector3.Distance(pos, realPos);

                            if (val > MeshFactory.isolevel)
                                v = 10f - ((dist / (float)size) * 5f);
                            if (val < MeshFactory.isolevel)
                                v = 10f + ((dist / (float)size) * 5f);

                        }

                        editNode.setDensityFromWorldPos(realPos, val);
                        editNode.setMaterialFromWorldPos(realPos, materialID);

                    }
                }
            }

            applyPaint(type, size + 1, pos, false);
            for (int i = 0; i < changedNodes.Count; i++)
                changedNodes[i].regenerateChunk();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies 'paint' to the area around the brush.
        /// </summary>
        /// <param name="type">The type/shape of the brush.</param>
        /// <param name="size">The size (radius) of the brush.</param>
        /// <param name="pos">The (real world) position to apply the brush.</param>
        /// <param name="regen">Set to true to have the engine regen the chunk after painting.</param>
        public static void applyPaint(BrushType type, int size, Vector3 pos, bool regen)
        {
            List<Node> changedNodes = new List<Node>();
            float nodeWidth = NodeManager.LODSize[0];
            Vector3 realPos = new Vector3();
            Vector3I point = new Vector3I((int)Math.Round(pos.x / nodeWidth),
                (int)Math.Round(pos.y / nodeWidth),
                (int)Math.Round(pos.z / nodeWidth));

            List<Vector3> points = getPoints(type, size, pos);
            for (int o = 0; o < points.Count; o++)
            {
                realPos = points[o];
                Node[] editNodes = NodeManager.searchNodeContainingDensity(realPos, 0);

                for (int i = 0; i < editNodes.Length; i++)
                {
                    Node editNode = editNodes[i];
                    if (editNode != null && editNode.LOD == 0)
                    {
                        if (!changedNodes.Contains(editNode))
                            changedNodes.Add(editNode);

                        editNode.setMaterialFromWorldPos(realPos, materialID);

                    }
                }
            }

            if (regen)
                for (int i = 0; i < changedNodes.Count; i++)
                    changedNodes[i].regenerateChunk();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of points inside of a given brush type and size.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="size"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        private static List<Vector3> getPoints(BrushType type, int size, Vector3 pos)
        {
            float nodeWidth = NodeManager.LODSize[0];
            Vector3I point = new Vector3I((int)Math.Round(pos.x / nodeWidth),
                (int)Math.Round(pos.y / nodeWidth),
                (int)Math.Round(pos.z / nodeWidth));

            List<Vector3> ret = new List<Vector3>();
            switch (type)
            {
                case BrushType.BOX:
                    for (int x = 0; x <= size; x++)
                    {
                        for (int y = 0; y <= size; y++)
                        {
                            for (int z = 0; z <= size; z++)
                            {
                                Vector3 realPos = new Vector3();
                                realPos.x = ((point.x + x) * nodeWidth);
                                realPos.y = ((point.y + y) * nodeWidth);
                                realPos.z = ((point.z + z) * nodeWidth);
                                ret.Add(realPos);
                            }
                        }
                    }
                    break;

                case BrushType.SPHERE:
                    for (int x = -size; x < size; x++)
                    {
                        for (int y = -size * 2; y < size; y++)
                        {
                            for (int z = -size; z < size; z++)
                            {
                                Vector3 realPos = new Vector3();
                                realPos.x = ((point.x + x) * nodeWidth);
                                realPos.y = ((point.y + y) * nodeWidth);
                                realPos.z = ((point.z + z) * nodeWidth);

                                if (Vector3.Distance(realPos, pos) < size * nodeWidth)
                                {
                                    ret.Add(realPos);
                                }
                            }
                        }
                    }
                    break;
            }

            return ret;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Calculates the normal.
 /// </summary>
 /// <param name="p"></param>
 private static Vector3 calculateDensityNormal(Vector3I p, DensityData densities, int lod)
 {
     Vector3 normal = new Vector3();
     normal.x = (densities.get(p.x + 1, p.y, p.z) - densities.get(p.x - 1, p.y, p.z)) / (NodeManager.LODSize[lod]);
     normal.y = (densities.get(p.x, p.y + 1, p.z) - densities.get(p.x, p.y - 1, p.z)) / (NodeManager.LODSize[lod]);
     normal.z = (densities.get(p.x, p.y, p.z + 1) - densities.get(p.x, p.y, p.z - 1)) / (NodeManager.LODSize[lod]);
     normal.Normalize();
     return normal;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates the triangles for a specific voxel
        /// </summary>
        /// <param name="node">The node that contains the voxel</param>
        /// <param name="pos">The voxel position (Not real position) [16,16,16]</param>
        /// <param name="triangleList">The list used to contain triangles made so far</param>
        /// <param name="densities">The array that contains density information</param>
        /// <param name="densityNormals">The array that contains density normals</param>
        private static void generateTriangles(Node node, Vector3I pos, List<Triangle> triangleList, List<int> submeshIDList, int[] subMeshTriCount, DensityData densities, Vector3[, ,] densityNormals)
        {
            float size = NodeManager.LODSize[node.LOD];

            float[] denses = new float[8];
            denses[0] = densities.get(pos.x, pos.y, pos.z + 1);
            denses[1] = densities.get(pos.x + 1, pos.y, pos.z + 1);
            denses[2] = densities.get(pos.x + 1, pos.y, pos.z);
            denses[3] = densities.get(pos.x, pos.y, pos.z);
            denses[4] = densities.get(pos.x, pos.y + 1, pos.z + 1);
            denses[5] = densities.get(pos.x + 1, pos.y + 1, pos.z + 1);
            denses[6] = densities.get(pos.x + 1, pos.y + 1, pos.z);
            denses[7] = densities.get(pos.x, pos.y + 1, pos.z);

            byte cubeIndex = 0;

            if (denses[0] < isolevel)
                cubeIndex |= 1;
            if (denses[1] < isolevel)
                cubeIndex |= 2;
            if (denses[2] < isolevel)
                cubeIndex |= 4;
            if (denses[3] < isolevel)
                cubeIndex |= 8;
            if (denses[4] < isolevel)
                cubeIndex |= 16;
            if (denses[5] < isolevel)
                cubeIndex |= 32;
            if (denses[6] < isolevel)
                cubeIndex |= 64;
            if (denses[7] < isolevel)
                cubeIndex |= 128;

            if (cubeIndex == 0 || cubeIndex == 255)
                return;

            Vector3 origin = new Vector3((size * (pos.x))
                , (size * (pos.y))
                , (size * (pos.z)));

            Vector3[] positions = new Vector3[8];
            positions[0] = new Vector3(origin.x, origin.y, origin.z + size);
            positions[1] = new Vector3(origin.x + size, origin.y, origin.z + size);
            positions[2] = new Vector3(origin.x + size, origin.y, origin.z);
            positions[3] = new Vector3(origin.x, origin.y, origin.z);
            positions[4] = new Vector3(origin.x, origin.y + size, origin.z + size);
            positions[5] = new Vector3(origin.x + size, origin.y + size, origin.z + size);
            positions[6] = new Vector3(origin.x + size, origin.y + size, origin.z);
            positions[7] = new Vector3(origin.x, origin.y + size, origin.z);

            Vector3[][] vertlist = new Vector3[12][];
            if (IsBitSet(edgeTable[cubeIndex], 1))
                vertlist[0] = VertexInterp(isolevel, positions[0], positions[1], denses[0], denses[1], densityNormals[pos.x, pos.y, pos.z + 1], densityNormals[pos.x + 1, pos.y, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 2))
                vertlist[1] = VertexInterp(isolevel, positions[1], positions[2], denses[1], denses[2], densityNormals[pos.x + 1, pos.y, pos.z + 1], densityNormals[pos.x + 1, pos.y, pos.z]);
            if (IsBitSet(edgeTable[cubeIndex], 4))
                vertlist[2] = VertexInterp(isolevel, positions[2], positions[3], denses[2], denses[3], densityNormals[pos.x + 1, pos.y, pos.z], densityNormals[pos.x, pos.y, pos.z]);
            if (IsBitSet(edgeTable[cubeIndex], 8))
                vertlist[3] = VertexInterp(isolevel, positions[3], positions[0], denses[3], denses[0], densityNormals[pos.x, pos.y, pos.z], densityNormals[pos.x, pos.y, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 16))
                vertlist[4] = VertexInterp(isolevel, positions[4], positions[5], denses[4], denses[5], densityNormals[pos.x, pos.y + 1, pos.z + 1], densityNormals[pos.x + 1, pos.y + 1, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 32))
                vertlist[5] = VertexInterp(isolevel, positions[5], positions[6], denses[5], denses[6], densityNormals[pos.x + 1, pos.y + 1, pos.z + 1], densityNormals[pos.x + 1, pos.y + 1, pos.z]);
            if (IsBitSet(edgeTable[cubeIndex], 64))
                vertlist[6] = VertexInterp(isolevel, positions[6], positions[7], denses[6], denses[7], densityNormals[pos.x + 1, pos.y + 1, pos.z], densityNormals[pos.x, pos.y + 1, pos.z]);
            if (IsBitSet(edgeTable[cubeIndex], 128))
                vertlist[7] = VertexInterp(isolevel, positions[7], positions[4], denses[7], denses[4], densityNormals[pos.x, pos.y + 1, pos.z], densityNormals[pos.x, pos.y + 1, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 256))
                vertlist[8] = VertexInterp(isolevel, positions[0], positions[4], denses[0], denses[4], densityNormals[pos.x, pos.y, pos.z + 1], densityNormals[pos.x, pos.y + 1, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 512))
                vertlist[9] = VertexInterp(isolevel, positions[1], positions[5], denses[1], denses[5], densityNormals[pos.x + 1, pos.y, pos.z + 1], densityNormals[pos.x + 1, pos.y + 1, pos.z + 1]);
            if (IsBitSet(edgeTable[cubeIndex], 1024))
                vertlist[10] = VertexInterp(isolevel, positions[2], positions[6], denses[2], denses[6], densityNormals[pos.x + 1, pos.y, pos.z], densityNormals[pos.x + 1, pos.y + 1, pos.z]);
            if (IsBitSet(edgeTable[cubeIndex], 2048))
                vertlist[11] = VertexInterp(isolevel, positions[3], positions[7], denses[3], denses[7], densityNormals[pos.x, pos.y, pos.z], densityNormals[pos.x, pos.y + 1, pos.z]);

            int submesh = densities.getMaterial(pos.x, pos.y, pos.z);
            for (int i = 0; triTable[cubeIndex][i] != -1; i += 3)
            {
                submeshIDList.Add(submesh);
                subMeshTriCount[submesh] = subMeshTriCount[submesh] + 1;
                triangleList.Add(new Triangle(vertlist[triTable[cubeIndex][i]][0], vertlist[triTable[cubeIndex][i + 1]][0], vertlist[triTable[cubeIndex][i + 2]][0],
                    vertlist[triTable[cubeIndex][i]][1], vertlist[triTable[cubeIndex][i + 1]][1], vertlist[triTable[cubeIndex][i + 2]][1]));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public static void init(string worldName)
        {
            NodeManager.worldName = worldName;
            float nSize = LODSize[maxLOD] * nodeSize;
            for (int x = -1; x < 2; x++)
            {
                for (int y = -1; y < 2; y++)
                {
                    for (int z = -1; z < 2; z++)
                    {
                        topNodes[x + 1, y + 1, z + 1] = new Node(null,
                            new Vector3(x * nSize,
                                y * nSize,
                                z * nSize),
                            0, maxLOD, Node.RenderType.FRONT);
                    }
                }
            }

            viewChunkPos = new Vector3I[maxLOD + 1];
            for (int i = 0; i <= maxLOD; i++)
                viewChunkPos[i] = new Vector3I();
            //这几句是做一个初始设定,下面的setViewPosition就是具体设置
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Calculates a density value given a location
        /// </summary>
        /// <param name="node"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        private static VoxelData calculateDensity(Node node, Vector3I pos)
        {
            int nodeWidth = NodeManager.LODSize[node.LOD];
            Vector3 ws = new Vector3(node.position.x + (nodeWidth * pos.x),
                node.position.y + (nodeWidth * pos.y),
                node.position.z + (nodeWidth * pos.z));

            return terrainGenerator.calculateDensity(ws);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when the viewpoint has changed.
        /// </summary>
        /// <param name="pos"></param>
        public void viewPosChanged(Vector3 pos)
        {
            //float sep = 10f;

            //float distance = ((center.x - pos.x) * (center.x - pos.x) +
            //(center.y - pos.y) * (center.y - pos.y) +
            //(center.z - pos.z) * (center.z - pos.z));

            //if (distance < (((float)NodeManager.LODRange[LOD]) * sep) * (((float)NodeManager.LODRange[LOD]) * sep))
            Vector3I viewPos = NodeManager.viewChunkPos[LOD];
            int size = 1;
            if ((viewPos.x >= chunkPos.x - size && viewPos.x <= chunkPos.x + size)
                && (viewPos.y >= chunkPos.y - size && viewPos.y <= chunkPos.y + size)
                && (viewPos.z >= chunkPos.z - size && viewPos.z <= chunkPos.z + size))
            {
                if (isBottomLevel())
                    createSubNodes(RenderType.FRONT);

                for (int i = 0; i < 8; i++)
                {
                    if (subNodes[i] != null)
                        subNodes[i].viewPosChanged(pos);
                }
            }
            //else if (!permanent)
            else
            {
                size += 2;
                if (LOD < 3 && (viewPos.x < chunkPos.x - size || viewPos.x > chunkPos.x + size)
                    || (viewPos.y < chunkPos.y - size || viewPos.y > chunkPos.y + size)
                    || (viewPos.z < chunkPos.z - size || viewPos.z > chunkPos.z + size))
                {
                    for (int i = 0; i < 8; i++)
                    {
                        if (subNodes[i] != null)
                        {
                            subNodes[i].dispose();
                            subNodes[i] = null;
                        }
                    }
                }
                else if (LOD >= 3)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        if (subNodes[i] != null)
                        {
                            subNodes[i].dispose();
                            subNodes[i] = null;
                        }
                    }
                }
            }

            if (LOD == 0)
            {
                float nodeSize = (float)NodeManager.LODSize[0] * (float)NodeManager.nodeSize;
                Vector3I viewChunk = new Vector3I((int)(pos.x / nodeSize),
                    (int)(pos.y / nodeSize),
                    (int)(pos.z / nodeSize));

                Vector3I curChunk = new Vector3I((int)(position.x / nodeSize),
                    (int)(position.y / nodeSize),
                    (int)(position.z / nodeSize));

                if (curChunk.x >= viewChunk.x - 3 && curChunk.x <= viewChunk.x + 3 &&
                    curChunk.y >= viewChunk.y - 3 && curChunk.y <= viewChunk.y + 3 &&
                    curChunk.z >= viewChunk.z - 3 && curChunk.z <= viewChunk.z + 3)
                {
                    collides = true;
                    if (chunk != null)
                    {
                        chunk.GetComponent<MeshCollider>().sharedMesh = chunk.GetComponent<MeshFilter>().sharedMesh;
                    }
                }
            }

            renderCheck();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns a 3d integer vector position of the "top" (highest LOD) node that contains the given position.
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static Vector3I getTopNode(Vector3 pos)
        {
            Vector3I ret = new Vector3I();
            ret.x = (int)Mathf.Floor(pos.x / (NodeManager.LODSize[maxLOD] * nodeSize));
            ret.y = (int)Mathf.Floor(pos.y / (NodeManager.LODSize[maxLOD] * nodeSize));
            ret.z = (int)Mathf.Floor(pos.z / (NodeManager.LODSize[maxLOD] * nodeSize));

            return ret;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets the density of a point, given a world pos.
        /// </summary>
        /// <param name="worldPos"></param>
        public void setDensityFromWorldPos(Vector3 worldPos, float val)
        {
            worldPos = worldPos - position;
            Vector3I arrayPos = new Vector3I((int)Math.Round(worldPos.x) / NodeManager.LODSize[LOD],
                                            (int)Math.Round(worldPos.y) / NodeManager.LODSize[LOD],
                                            (int)Math.Round(worldPos.z) / NodeManager.LODSize[LOD]);

            if (arrayPos.x < -1 || arrayPos.x > 17 ||
                arrayPos.y < -1 || arrayPos.y > 17 ||
                arrayPos.z < -1 || arrayPos.z > 17)
            {
                Debug.Log("Wrong node. " + arrayPos + ":" + worldPos + ":" + containsDensityPoint(worldPos).ToString());
                return;
            }

            densityChangeData.set(arrayPos.x, arrayPos.y, arrayPos.z, val);
            setPermanence(true);

            hasDensityChangeData = true;
            MeshFactory.requestSave(this);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Sets the material of the voxel at the given world position.
        /// </summary>
        /// <param name="worldPos"></param>
        /// <param name="val"></param>
        public void setMaterialFromWorldPos(Vector3 worldPos, byte val)
        {
            worldPos = worldPos - position;
            Vector3I arrayPos = new Vector3I((int)Math.Round(worldPos.x) / NodeManager.LODSize[LOD],
                                            (int)Math.Round(worldPos.y) / NodeManager.LODSize[LOD],
                                            (int)Math.Round(worldPos.z) / NodeManager.LODSize[LOD]);

            if (arrayPos.x < -1 || arrayPos.x > 17 ||
                arrayPos.y < -1 || arrayPos.y > 17 ||
                arrayPos.z < -1 || arrayPos.z > 17)
            {
                Debug.Log("Wrong node. " + arrayPos);
                return;
            }

            bool change = (densityChangeData.getMaterial(arrayPos.x, arrayPos.y, arrayPos.z) != val);
            densityChangeData.setMaterial(arrayPos.x, arrayPos.y, arrayPos.z, val);

            if (change)
            {
                setPermanence(true);
                hasDensityChangeData = true;
                MeshFactory.requestSave(this);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the view position, and checks if chunks need to be updated
        /// </summary>
        /// <param name="pos"></param>
        public static void setViewPosition(Vector3 pos)
        {
            for (int i = 0; i <= maxLOD; i++)
            {
                float nWidth = LODSize[i] * nodeSize;
                viewChunkPos[i].x = (int)(pos.x / nWidth);
                viewChunkPos[i].y = (int)(pos.y / nWidth);
                viewChunkPos[i].z = (int)(pos.z / nWidth);
            }

            float sWidth = LODSize[0] * nodeSize * 0.5f;
            Debug.Log(sWidth);
            Vector3I newPos = new Vector3I((int)(pos.x / sWidth), (int)(pos.y / sWidth), (int)(pos.z / sWidth));

            if (!curTopNode.Equals(getTopNode(pos)))
            {
                float nodeWidth = LODSize[maxLOD] * nodeSize;
                Vector3I diff = getTopNode(pos).Subtract(curTopNode);
                curTopNode = getTopNode(pos);
                while (diff.x > 0)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        for (int z = 0; z < 3; z++)
                        {
                            topNodes[0, y, z].dispose();
                            topNodes[0, y, z] = topNodes[1, y, z];
                            topNodes[1, y, z] = topNodes[2, y, z];
                            topNodes[2, y, z] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) + nodeWidth,
                                                    (curTopNode.y * nodeWidth) + ((y - 1) * nodeWidth),
                                                    (curTopNode.z * nodeWidth) + ((z - 1) * nodeWidth)),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }
                    diff.x--;
                }

                while (diff.x < 0)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        for (int z = 0; z < 3; z++)
                        {
                            topNodes[2, y, z].dispose();
                            topNodes[2, y, z] = topNodes[1, y, z];
                            topNodes[1, y, z] = topNodes[0, y, z];
                            topNodes[0, y, z] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) - nodeWidth,
                                                    (curTopNode.y * nodeWidth) + ((y - 1) * nodeWidth),
                                                    (curTopNode.z * nodeWidth) + ((z - 1) * nodeWidth)),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }
                    diff.x++;
                }

                while (diff.y > 0)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        for (int z = 0; z < 3; z++)
                        {
                            topNodes[x, 0, z].dispose();
                            topNodes[x, 0, z] = topNodes[x, 1, z];
                            topNodes[x, 1, z] = topNodes[x, 2, z];
                            topNodes[x, 2, z] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) + ((x - 1) * nodeWidth),
                                                    (curTopNode.y * nodeWidth) + nodeWidth,
                                                    (curTopNode.z * nodeWidth) + ((z - 1) * nodeWidth)),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }
                    diff.y--;
                }

                while (diff.y < 0)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        for (int z = 0; z < 3; z++)
                        {
                            topNodes[x, 2, z].dispose();
                            topNodes[x, 2, z] = topNodes[x, 1, z];
                            topNodes[x, 1, z] = topNodes[x, 0, z];
                            topNodes[x, 0, z] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) + ((x - 1) * nodeWidth),
                                                    (curTopNode.y * nodeWidth) - nodeWidth,
                                                    (curTopNode.z * nodeWidth) + ((z - 1) * nodeWidth)),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }

                    diff.y++;
                }

                while (diff.z > 0)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 3; y++)
                        {
                            topNodes[x, y, 0].dispose();
                            topNodes[x, y, 0] = topNodes[x, y, 1];
                            topNodes[x, y, 1] = topNodes[x, y, 2];
                            topNodes[x, y, 2] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) + ((x - 1) * nodeWidth),
                                                    (curTopNode.y * nodeWidth) + ((y - 1) * nodeWidth),
                                                    (curTopNode.z * nodeWidth) + nodeWidth),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }

                    diff.z--;
                }

                while (diff.z < 0)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 3; y++)
                        {
                            topNodes[x, y, 2].dispose();
                            topNodes[x, y, 2] = topNodes[x, y, 1];
                            topNodes[x, y, 1] = topNodes[x, y, 0];
                            topNodes[x, y, 0] = new Node(null,
                                                new Vector3((curTopNode.x * nodeWidth) + ((x - 1) * nodeWidth),
                                                    (curTopNode.y * nodeWidth) + ((y - 1) * nodeWidth),
                                                    (curTopNode.z * nodeWidth) - nodeWidth),
                                                0, maxLOD, Node.RenderType.FRONT);
                        }
                    }
                    diff.z++;
                }
            }

            if (curBottomNode.x != newPos.x || curBottomNode.y != newPos.y || curBottomNode.z != newPos.z)
            {
                Vector3 setPos = new Vector3(newPos.x * sWidth + (sWidth / 1f), newPos.y * sWidth + (sWidth / 1f), newPos.z * sWidth + (sWidth / 1f));
                for (int x = 0; x < 3; x++)
                    for (int y = 0; y < 3; y++)
                        for (int z = 0; z < 3; z++)
                        {
                            topNodes[x, y, z].viewPosChanged(setPos);
                        }

                curBottomNode = newPos;
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds another vector's values to this
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public Vector3I Add(Vector3I other)
 {
     return new Vector3I(x + other.x, y + other.y, z + other.z);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Sets the density value at the given coordinates.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <returns></returns>
 public void set(Vector3I pos, float val)
 {
     set(pos.x, pos.y, pos.z, val);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns the density value at the given coordinates.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public float get(Vector3I pos)
        {
            if (changeData != null)
                if (changeData.get(pos) > -99999f)
                    return changeData.get(pos);

            return get(pos.x, pos.y, pos.z);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Subtracts another vectory's values from this
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public Vector3I Subtract(Vector3I other)
 {
     return new Vector3I(x - other.x, y - other.y, z - other.z);
 }