0 votes

I've just started using C++ and Godot. I believe in learning as you do and as such run into walls sometimes, like now. I just transcribed my GDScript into GDnativeScript, edited it a lil and it's stopped working. Any pointers into what I've done wrong?

enter image description here

GDScript:

extends MeshInstance
export(Material) var material = null

func _ready():
    var surftool = SurfaceTool.new()
    print(typeof(surftool))
    var mesh = Mesh.new()
    print(typeof(mesh))
    #surftool.clear()

    surftool.begin(Mesh.PRIMITIVE_TRIANGLES)
    surftool.set_material(material)
    surftool.add_vertex(Vector3(-25,-10,25))
    surftool.add_vertex(Vector3(25,-10,-25))
    surftool.add_vertex(Vector3(-25,-10,-25))

    surftool.add_vertex(Vector3(-25,0,-25))
    surftool.add_vertex(Vector3(25,0,-25))
    surftool.add_vertex(Vector3(-25,0,25))

    surftool.generate_normals()
    surftool.index()

    surftool.commit(mesh)
    set_mesh(mesh)

    create_trimesh_collision()
    #get_node("StaticBody").shape.margin = 0.1

GDNativeScript:

#include "TerrainMesh.h"
#include <math.h>    
using namespace godot;

    void TerrainMesh::_register_methods() {
        register_method("_process", &TerrainMesh::_process);
    }

    TerrainMesh::TerrainMesh() {
    }

    TerrainMesh::~TerrainMesh() {
        // add your cleanup here
    }

    void TerrainMesh::_init() {
        // initialize any variables here
        //float heightMap[240][240];
        Ref<godot::SurfaceTool> surftool;
        surftool.instance();

        Ref<godot::Mesh> mesh;
        //mesh.instance();

        surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
        //surftool.set_material(

        for(int x=1; x<=100; x++){
            for(int y=1; y<=100; y++){
                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x, 0, y));
                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x+1, 0, y));
                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x, 0, y+1));

                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x+1, 0, y));
                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x+1, 0, y+1));
                surftool->add_normal(Vector3(0, 1, 0));
                surftool->add_uv(Vector2(0, 0));
                surftool->add_vertex(Vector3(x, 0, y+1));

            }
        }
        surftool->index();
        surftool->commit(mesh);
        set_mesh(mesh);
        create_trimesh_collision();
    }

    void TerrainMesh::_process(float delta) {


    }
asked Jul 3, 2019 in Engine by AutarkOS (17 points)

It seems you didnt instanciate your mesh? No mesh, no trimesh, no body?

Gonna be honest, I just fiddled it till the compiler stopped giving errors. this is what happens when i instance it.

enter image description here

That's still a compilation error, but I don't really understand what's going on here. It's getting confused here https://github.com/GodotNativeTools/godot-cpp/blob/971adbd95590d29d17df621d5a04094b173c77f3/include/core/Ref.hpp#L190

You might want to ask why specifically Ref<godot::Mesh> cannot instanciate on the Godot-Cpp repo on Github https://github.com/GodotNativeTools/godot-cpp/issues
to Karroffel or BastiaanOlij.

I've been having the same problem, so I just want to second how weird this is, so if anyone has come up with solutions for or thoughts about this I'd love to know.

Here's my code:

mesh_node.mesh = _generate_mesh()
mesh_node.create_trimesh_collision()

where generatemesh() is

_generate_vertices()
_generate_UVs()
_generate_indices()
_generate_normals()
var mesh = ArrayMesh.new()
var data = []
data.resize(ArrayMesh.ARRAY_MAX)
data[ArrayMesh.ARRAY_VERTEX] = vertices
data[ArrayMesh.ARRAY_TEX_UV] = UVs
data[ArrayMesh.ARRAY_INDEX] = indices
data[ArrayMesh.ARRAY_NORMAL] = normals
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLE_STRIP, data)

Additionally, if I call mesh_node.create_convec_collision() I end up with this error spam:

 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.
 core/math/quick_hull.cpp:428 - Condition "!F2" is true. Continuing.
 core/math/quick_hull.cpp:401 - Condition "O == E" is true. Continuing.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.