Exemplo n.º 1
0
 public CubeModifier(VoxelTree control, Vector3 worldPosition, Vector3 worldDimensions, VoxelHolder value, bool updateMesh)
     : base(control, updateMesh)
 {
     this.value = value.toVoxel();
     Vector3 dimensions = worldDimensions / control.voxelSize();
     min = control.transform.InverseTransformPoint(worldPosition) / control.voxelSize() - dimensions /2 -Vector3.one *0.5f;
     max = min + dimensions;
     setMinMax(min, max);
     //			apply();
 }
Exemplo n.º 2
0
        public CubeModifier(VoxelTree control, Vector3 worldPosition, Vector3 worldDimensions, VoxelHolder value, bool updateMesh)
            : base(control, updateMesh)
        {
            this.value = value.toVoxel();
            Vector3 dimensions = worldDimensions / control.voxelSize();

            min = control.transform.InverseTransformPoint(worldPosition) / control.voxelSize() - dimensions / 2 - Vector3.one * 0.5f;
            max = min + dimensions;
            setMinMax(min, max);
//			apply();
        }
Exemplo n.º 3
0
        public void genMesh(VoxelUpdateInfo info)
        {
            if (control == null)
            {
                return;
            }

            size = info.size;

            Queue <int[]> triangleSet = new Queue <int[]>();

            vertices          = new Dictionary <int, object>();
            vertexSubstances  = new Dictionary <int, byte>();
            Voxel[, ,] voxels = createVoxelArray(info);
            MarchingCubes.setup(info.size / VOXEL_DIMENSION, control.isoLevel, ref vertices, ref vertexSubstances, ref voxels, position - new Vector3(0.5f, 0.5f, 0.5f) * size / VOXEL_DIMENSION, null);
            int totalTris = 0;

            for (byte x = (byte)(1 - xExtend), x1 = (byte)(x + 1); x1 < xDim; x = x1++)
            {
                for (byte y = (byte)(1 - yExtend), y1 = (byte)(y + 1); y1 < yDim; y = y1++)
                {
                    for (byte z = (byte)(1 - zExtend), z1 = (byte)(z + 1); z1 < zDim; z = z1++)
                    {
                        lock (control) {
                            VoxelHolder block = info.getSub(VOXEL_COUNT_POWER, VOXEL_DIMENSION + x, VOXEL_DIMENSION + y, VOXEL_DIMENSION + z);
                            voxels[x1, y1, z1] = block.toVoxel();
                            int[] tris = MarchingCubes.lookupTriangles(x, y, z, x1, y1, z1);
                            if (tris == null)
                            {
                                continue;
                            }
                            triangleSet.Enqueue(tris);
                            totalTris += tris.Length;
                        }
                    }
                }
            }

            if (vertices.Count < 1)
            {
                applied = true;
                return;
            }


            List <int>     triangles     = new List <int>();
            List <Vector3> finalVertices = new List <Vector3>(vertices.Count);

            //List<byte> finalMats = new List<byte>(vertices.Count);
            while (triangleSet.Count > 0)
            {
                int[] triangleList = triangleSet.Dequeue();
                for (int i = 0; i < triangleList.Length; ++i)
                {
                    if (vertices[triangleList[i]].GetType() == typeof(Vector3))
                    {
                        finalVertices.Add((Vector3)vertices[triangleList[i]]);
                        //finalMats.Add(vertexSubstances[triangleList[i]]);
                        vertices[triangleList[i]] = finalVertices.Count - 1;
                    }
                    triangles.Add((int)vertices[triangleList[i]]);
                }
            }
            VERTS = finalVertices.ToArray();
            TRIS  = triangles.ToArray();
            //MATS = finalMats.ToArray();
            calcNorms();

            alignEdge(info, 0, 1, 1);
            alignEdge(info, 2, 1, 1);
            alignEdge(info, 1, 0, 1);
            alignEdge(info, 1, 2, 1);
            alignEdge(info, 1, 1, 0);
            alignEdge(info, 1, 1, 2);
            lock (control) {
                control.enqueueJob(new ApplyMeshJob(this, info.detailLevel, info.x, info.y, info.z));
            }
        }
Exemplo n.º 4
0
 public CubeMutator(Tree control, Vector3 worldPosition, Vector3 worldDimensions, VoxelHolder value, bool updateMesh)
 {
     this.worldPosition   = worldPosition;
     this.worldDimensions = worldDimensions;
     this.value           = value.toVoxel();
 }
 public CubeMutator(OcTree control, Vector3 worldPosition, Vector3 worldDimensions, VoxelHolder value, bool updateMesh)
 {
     this.worldPosition = worldPosition;
     this.worldDimensions = worldDimensions;
     this.value = value.toVoxel();
 }