Mesh Component

There’s not really much difference between them, other than that the Model has some more features (i.e. skinning).

2 Likes

I would second the index buffer request :wink: Would make life a touch simpler.

3 Likes

I’ve been trying to make a gameobject, that generates a vertex buffer on init. That works fine. The problem is, whenever I create another another instance of the go (either through factory or just plonking more in in the collection editor), the previous ones get the same vertices. I’m guessing it’s because all the meshes have the same .buffer file, and it’s that that is getting updated. Is it possible to create instances of a go with different vertex buffers at runtime somehow?

I guess this question got lost in the shuffle.

I believe the short answer is, “No”.
But the long answer is, you need to decide how many buffers you will need, max, and create a buffer file for each one in the editor, and load each one—either with a mesh component or a script property.

go.property("buf1", resource.buffer("/main/common/meshes/buffer1.buffer"))
go.property("buf2", resource.buffer("/main/common/meshes/buffer2.buffer"))
go.property("buf3", resource.buffer("/main/common/meshes/buffer3.buffer"))
go.property("buf4", resource.buffer("/main/common/meshes/buffer4.buffer"))

You can save these properties in a module for other scripts to use.

5 Likes

Thanks, figured something like this out as well. Shame there isn’t a nicer way, but eh, this works as well.

1 Like

I’m trying to take advantage of meshes in the “world” vertex space as the direct replacement of built-in sprites (to make some stunning fx, actually).

Is this the right way to change a buffer in a mesh?

go.property("buf", resource.buffer("/assets/meshes/star.buffer"))
-- ...
go.set("#mesh", "vertices", self.buf)

I’m asking about this because the game reports about leaked resources on shutdown:

ERROR:RESOURCE: Leaked resources:
ERROR:RESOURCE: Resource: /assets/meshes/gun.bufferc  ref count: 125
ERROR:RESOURCE: Resource: /assets/meshes/ball.bufferc  ref count: 125
ERROR:RESOURCE: Resource: /assets/meshes/eye.bufferc  ref count: 150
ERROR:RESOURCE: Resource: /assets/meshes/star.bufferc  ref count: 125

Is this a bug, or am I doing something wrong?

I attached the demo project:
issue_mesh_buf_change.zip (51.1 KB)

5 Likes

So I found a bug today: If you spawn a mesh, then try to set the same buffer that is already set on it, it stops rendering. I’ll validate this tomorrow and open an issue about it.

go.set("#mesh", "vertices", go.get("#mesh", "vertices))

5 Likes

I think that use case looks good.
I think you’ve found a bug, and thanks for the repro case! (Added Issue #6054))

4 Likes

Thanks!
Added Issue #6055 for this.

4 Likes

@dapetcu21 I’m unable to reproduce this problem. I’ve added a small example to the GitHub issue. Could you please take a look and see how it differs from your case?

1 Like

Sure. I’ll check it out later today

2 Likes

Solved in 1.2.189!

5 Likes

Is mesh should update itself, when i manipulate buffer in runtime?

In my case i should update it by myself.
1)Buffer created in cpp.
2)Set go buffer to new buffer

 resource.set_buffer(e.light_go.mesh.vertices, e.light_native:GetBuffer())

2)Modify vertices is cpp.
3)Call dmBuffer::UpdateContentVersion
4)Mesh draw prev data.
5)Check content version by myself and set buffer.

local buffer_version = e.light_native:BufferGetContentVersion()
if(buffer_version ~= e.light_go.mesh.buffer_version)then
        e.light_go.mesh.buffer_version = buffer_version
        resource.set_buffer(e.light_go.mesh.vertices, e.light_native:GetBuffer())
end

is this approach working for you? can you share some NE code?

I describe my solution. Is that what you need?
1)buffer have method for updating content version. In cpp

 dmBuffer::UpdateContentVersion(this->buffer);

2)I make method to get content version from cpp to lua

static int BufferGetContentVersion(lua_State *L){
    game_utils::check_arg_count(L, 1);
    Light *light = Light_get_userdata_safe(L, 1);
    uint32_t version = 0;
    dmBuffer::Result result = dmBuffer::GetContentVersion(light->buffer, &version);
    lua_pushnumber(L, version);
    return 1;
};

3)In lua i set buffer if content version is changed.

local buffer_version = e.light_native:BufferGetContentVersion()
if(buffer_version ~= e.light_go.mesh.buffer_version)then
        e.light_go.mesh.buffer_version = buffer_version
        resource.set_buffer(e.light_go.mesh.vertices, e.light_native:GetBuffer())
end
3 Likes

Can we have detail explaination on how to export mesh buffer from blender, all the settings have to be made in blender to export shapes properly. I’m looking through sample blend file how all properties have done. Trying to do same while exporting mesh buffer but in defold not getting proper result. Textures are not showing.

The mesh export is mostly for runtime manipulation of the mesh, and the export script is an example of that.

Are you planning on changing the vertices in any way at runtime, or can you use the regular Model component with .gltf files? It might be a bit easier?

2 Likes

Yes, I’m changing vertices at runtime. I just need to look structure of buffer of the shape I’m creating. To help create buffer at runtime referenceing structure of mesh buffer from blender shape.

For reference dealing with some shape like this when dragging the edge changing mesh at runtime.


How vertex positions fill in screen the start point and end point when creating shapes. If I want to create polygon shapes with even more dense shapes then above images. How to create vertex positions map that make that shape. Or any other tips.

Regarding debugging your setup, do you have texture coordinates in your blender scene?
What does your output .buffer file look like?

Yes, finally understand how to properly export mesh buffer to defold. Also get it how to set texture coordinates.


I’m not good with blender also. Didn’t know that I have to tap assign button assign texture.

2 Likes