Exemplo n.º 1
0
    public void MeshChunk(Chunk chunk, ArrayPool <Position> pool)
    {
        RawChunk rawChunk = new RawChunk();

        rawChunk.arrays        = new Godot.Collections.Array[chunk.Materials - 1];
        rawChunk.materials     = new SpatialMaterial[chunk.Materials - 1];
        rawChunk.colliderFaces = new Vector3[chunk.Materials - 1][];

        if (chunk.Materials > 1)
        {
            rawChunk = Meshing(chunk, rawChunk, pool);
        }
        else
        {
            rawChunk = FastGodotCube(chunk, rawChunk);
        }

        RID meshID = VisualServer.MeshCreate();

        //RID body = PhysicsServer.BodyCreate (PhysicsServer.BodyMode.Static);

        for (int t = 0; t < rawChunk.arrays.Count(); t++)
        {
            SpatialMaterial material = rawChunk.materials[t];

            Godot.Collections.Array godotArray = rawChunk.arrays[t];

            if (godotArray.Count > 0)
            {
                /*  RID shape = PhysicsServer.ShapeCreate (PhysicsServer.ShapeType.ConcavePolygon);
                 * //            PhysicsServer.ShapeSetData (shape, vertice);
                 *
                 * PhysicsServer.BodyAddShape (body, shape, new Transform (Transform.basis, new Vector3 (chunk.x, chunk.y, chunk.z)));
                 */
                VisualServer.MeshAddSurfaceFromArrays(meshID, VisualServer.PrimitiveType.Triangles, godotArray);
                VisualServer.MeshSurfaceSetMaterial(meshID, VisualServer.MeshGetSurfaceCount(meshID) - 1, material.GetRid());
            }
        }

        RID instance = VisualServer.InstanceCreate();

        VisualServer.InstanceSetBase(instance, meshID);
        VisualServer.InstanceSetTransform(instance, new Transform(Transform.basis, new Vector3(chunk.x, chunk.y, chunk.z)));
        VisualServer.InstanceSetScenario(instance, GetWorld().Scenario);
        //   PhysicsServer.BodySetSpace (body, GetWorld ().Space);
    }