示例#1
0
 public MeshJobData(int3 dimensions,
                    bool includeLighting,
                    NativeArray <VoxelTypeID> voxels,
                    NativeArray <RotatedVoxelEntry> rotatedVoxels,
                    NativeArray <LightValue> lights,
                    NeighbourData neighbourData,
                    NativeMeshDatabase meshDatabase,
                    NativeVoxelTypeDatabase voxelTypeDatabase,
                    Allocator allocator)
 {
     this.dimensions        = dimensions;
     this.includeLighting   = includeLighting;
     this.voxels            = voxels;
     this.rotatedVoxels     = rotatedVoxels;
     this.lights            = lights;
     this.neighbourData     = neighbourData;
     this.meshDatabase      = meshDatabase;
     this.voxelTypeDatabase = voxelTypeDatabase;
     vertices           = new NativeList <Vector3>(allocator);
     vertexColours      = new NativeList <Color>(allocator);
     uvs                = new NativeList <Vector3>(allocator);
     normals            = new NativeList <Vector3>(allocator);
     allTriangleIndices = new NativeList <int>(allocator);
     materialRuns       = new NativeList <MaterialRun>(allocator);
     collisionSubmesh   = new CollisionSubmeshDescriptor(allocator);
 }
示例#2
0
        /// <summary>
        /// Generate the database from a list of type data
        /// </summary>
        public static NativeMeshDatabase FromTypeData(List <VoxelTypeData> typeData)
        {
            List <Node>          allMeshNodesList             = new List <Node>();
            List <StartEndRange> nodesUsedByFacesList         = new List <StartEndRange>();
            List <int>           allRelativeTrianglesList     = new List <int>();
            List <StartEndRange> relativeTrianglesByFacesList = new List <StartEndRange>();
            List <bool>          isFaceSolidList = new List <bool>();

            List <StartEndRange> meshTypeRangesList           = new List <StartEndRange>();
            List <int>           voxelTypeToMeshTypeMapList   = new List <int>();
            List <ushort>        voxelTypeToMaterialIDMapList = new List <ushort>();

            List <bool> meshIdToIncludeBackfacesMapList = new List <bool>();

            Dictionary <SOMeshDefinition, int> uniqueMeshIDs = new Dictionary <SOMeshDefinition, int>();

            //AIR
            voxelTypeToMeshTypeMapList.Add(0);
            voxelTypeToMaterialIDMapList.Add(0);

            for (ushort voxelId = 1; voxelId < typeData.Count; voxelId++)
            {
                var item = typeData[voxelId];


                var SODef = item.definition.meshDefinition;
                if (!uniqueMeshIDs.TryGetValue(SODef, out var meshID))
                {
                    //New Unique mesh defintion
                    meshID = meshTypeRangesList.Count;
                    uniqueMeshIDs.Add(SODef, meshID);
                    StartEndRange meshTypeRange = new StartEndRange();
                    meshTypeRange.start = nodesUsedByFacesList.Count;

                    Flatten(SODef, allMeshNodesList, nodesUsedByFacesList, allRelativeTrianglesList, relativeTrianglesByFacesList, isFaceSolidList);

                    meshTypeRange.end = nodesUsedByFacesList.Count;
                    meshTypeRangesList.Add(meshTypeRange);
                    meshIdToIncludeBackfacesMapList.Add(SODef.includeBackfaces);
                }
                voxelTypeToMeshTypeMapList.Add(meshID);
                voxelTypeToMaterialIDMapList.Add(item.materialID);
            }

            NativeMeshDatabase nativeMeshDatabase = new NativeMeshDatabase();

            nativeMeshDatabase.allMeshNodes             = new NativeArray <Node>(allMeshNodesList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.nodesUsedByFaces         = new NativeArray <StartEndRange>(nodesUsedByFacesList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.allRelativeTriangles     = new NativeArray <int>(allRelativeTrianglesList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.relativeTrianglesByFaces = new NativeArray <StartEndRange>(relativeTrianglesByFacesList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.isFaceSolid                 = new NativeArray <bool>(isFaceSolidList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.meshTypeRanges              = new NativeArray <StartEndRange>(meshTypeRangesList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.voxelTypeToMeshTypeMap      = new NativeArray <int>(voxelTypeToMeshTypeMapList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.voxelTypeToMaterialIDMap    = new NativeArray <ushort>(voxelTypeToMaterialIDMapList.ToArray(), Allocator.Persistent);
            nativeMeshDatabase.meshIdToIncludeBackfacesMap = meshIdToIncludeBackfacesMapList.ToArray().ToNative(Allocator.Persistent);

            return(nativeMeshDatabase);
        }