Ejemplo n.º 1
0
    private void AddMesh()
    {
        Vector3[] vertices = new Vector3[] {
            new Vector3(-5f, 0f, -5f),
            new Vector3(5f, 0f, -5f),
            new Vector3(5f, 0f, 5f),
            new Vector3(-5f, 0f, 5f)
        };
        Vector3[] normals = new Vector3[] {
            Vector3.Up,
            Vector3.Up,
            Vector3.Up,
            Vector3.Up
        };
        int[] indices = new int[] { 0, 1, 2, 0, 2, 3 };

        Godot.Collections.Array meshData = new Godot.Collections.Array();
        meshData.Resize((int)Mesh.ArrayType.Max);
        meshData[(int)Mesh.ArrayType.Vertex] = vertices;
        meshData[(int)Mesh.ArrayType.Normal] = normals;
        meshData[(int)Mesh.ArrayType.Index]  = indices;

        _mesh = VisualServer.MeshCreate();
        VisualServer.MeshAddSurfaceFromArrays(_mesh, VisualServer.PrimitiveType.Triangles, meshData);

        _instance = VisualServer.InstanceCreate();
        VisualServer.InstanceSetBase(_instance, _mesh);

        RID scenario = GetWorld().Scenario;

        VisualServer.InstanceSetScenario(_instance, scenario);
    }
Ejemplo n.º 2
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);
    }