Brilliant release!
I’m curious what is the use case scenario for this?
Nice! Was expecting this one for quite a while.
Thank you!
It’s for cases where a lot of content generated outside of the editor without needs to be able to edit it in the editor.
We see more and more tools that can export content into Defold format, for example Tiled, Blender scripts or TrenchBroom.
If after export you have ready-for-use content you don’t want to edit in the editor it will be efficient to mark such content as read-only. That will make the editor much more responsive especially in cases when you have a ton of content.
If you have more questions feel free to ask and tag @mats.gisselson , he knows more about it and can explain it better.
We will add documentation about this soon!
I have no idea why. But defos not build in 1.4.2 beta.
But it worked with 1.4.1. Any ideas?
line 6:#include <atlbase.h>
/native/defos/src/defos_win.cpp
Line 6: In file included from upload/native/defos/src/defos_win.cpp:6:
use of undeclared identifier 'DispatchMessage'
DispatchMessage(&msg);
How to worked with mesh culling?
On my project in doesn’t worked:(
Same mat_frustum worked for sprites.
local mat_view = render3d.camera_view()
render.set_view(mat_view)
local mat_proj = self:get_perspective()
render.set_projection(mat_proj)
local mat_frustum = mat_proj * mat_view
--draw meshes
self.draw_opts.frustum = mat_frustum
render.draw(self.predicates.model, self.draw_opts)
self.draw_opts.frustum = nil
Sorry, the description wasn’t very informative. You need to manually set a bounding volume on the buffer I think. I’ll write up documentation and an example tomorrow.
Thanks, wait for example to make tests in game:)
Ohh. So if i have a 3d level with a lot of meshes, it don’t worked out of the box?
Correct. Given the dynamic nature of the buffers, we opted for letting the users set the bounding box manually since they already have that data.
This is strange. I don’t think we have vhanged that api. Perhaps we’ve accidentally changed some includes. We’ll have a look in the morning!
Just quickly looking at the includes, you could try moving the windows includes to the top, or before the ”dmsdk/sdk.h” in particular
I’ve now submitted a fix to the dmsdk/sdk.h
where I removed thread.h
(which I had added). A new beta build will show up within the hour.
Some more clarifications on where the AABB+meshes feature is currently at:
With the latest addition of the frustum culling of meshes, it allows us to set meta data to a buffer at runtime. This is done with either Lua: buffer.set_metadata(), or C++ dmBuffer::SetMetaData(). There are also getters.
The mesh component looks for a AABB meta data with 6 floats: (minx, miny, minz), (maxx, maxy, maxz)
An example in Lua:
buffer.set_metadata(buf, hash("AABB"), {0, 0, 0, 1, 1, 1}, buffer.VALUE_TYPE_FLOAT32)
Reasoning:
Since the meshes are mainly for dynamic use at runtime, we first focused on the runtime part of the meta data + culling. We recommend when updating the buffer with new vertices, to also update the bounding box accordingly.
Since the buffer format is very generic (could be a sound or anything you want it to be), we cannot reliably calculate a bounding box for you. Especially if you consider that the vertex data may be packed in any way. E.g. in a terrain patch, the data may very well be represented as
uint8_t x, z;
uint16_t y;
where the x/z are in a different space from y.
Further improvements can be made, such as storing meta data in the buffer resource. However, it might also be pointed out that the model component will have similar functionality if not more, with multi materials. We’ll also add frustum culling soon for models. And we’re also looking to implement instancing for models.
But, for now, if you are using static pre-created mesh buffers, you need to iterate over your vertices and calculate the AABB manually.
Try to worked with mesh. But it crashed:(
Sometimes i get buffer invalid. Sometimes i get crash.
Can’t dmBuffer::ValidateBuffer or dmBuffer::GetStream
In logs buffer look ok.
Any ideas?
DEBUG:SCRIPT: hash: [/scene_hub_4/meshes/office_6.004.bufferc]
DEBUG:SCRIPT: buffer.buffer(count = 2454, version = 0, { hash("position"),
buffer.VALUE_TYPE_FLOAT32, 3 }, { hash("normal"), buffer.VALUE_TYPE_FLOAT32, 3 }, { hash("texcoord0"), buffer.VALUE_TYPE_FLOAT32, 2 })
INFO:CRASH: Successfully wrote Crashdump to file: C:\Users\user\AppData\Roaming\Defold/_crash
ERROR:CRASH: CALL STACK:
ERROR:CRASH: 0 0x7FF79504CFE0 dmCrash::GenerateCallstack D:\a\defold\defold\engine\crash\src\backtrace_win32.cpp:144
ERROR:CRASH: 1 0x7FF79538235C _seh_filter_exe /tmp/job3421627433228567764/minkernel/crts/ucrt/src/appcrt/misc/exception_filter.cpp:219
ERROR:CRASH: 2 0x7FF7953CFF98 `__scrt_common_main_seh'::`1'::filt$0 d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
ERROR:CRASH: 3 0x7FF795346840 __C_specific_handler d:\agent\_work\4\s\src\vctools\crt\vcruntime\src\eh\riscchandler.cpp:290
ERROR:CRASH: 4 0x7FFB21792300 __chkstk <unknown>:0
ERROR:CRASH: 5 0x7FFB21741070 RtlRaiseException <unknown>:0
ERROR:CRASH: 6 0x7FFB21790F20 KiUserExceptionDispatcher <unknown>:0
ERROR:CRASH: 7 0x7FF7950C3E10 dmBuffer::ValidateBuffer D:\a\defold\defold\engine\dlib\src\dlib\buffer.cpp:324
ERROR:CRASH: Lua Callstack:
ERROR:CRASH: [C]:-1: in function mesh_set_aabb
ERROR:CRASH: world/game/levels/level_creator.lua:389: in function init_meshes
ERROR:CRASH: world/game/levels/level_creator.lua:258: in function <world/game/levels/level_creator.lua:150>
ERROR:CRASH:
INFO:CRASH: Successfully wrote Crashdump to file: C:\Users\user\AppData\Roaming\Defold/_crash
ERROR:CRASH: CALL STACK:
ERROR:CRASH: 0 0x7FF7950C3E10 dmBuffer::ValidateBuffer D:\a\defold\defold\engine\dlib\src\dlib\buffer.cpp:324
ERROR:CRASH: 1 0x7FF794FC2110 MeshSetAABB /tmp/job3421627433228567764/upload/native/game/src/extension.cpp:305
ERROR:CRASH: 2 0x7FF794FD429E lj_BC_FUNCC <unknown>:0
ERROR:CRASH: 3 0x7FF794FD5053 lj_ff_coroutine_resume <unknown>:0
ERROR:CRASH: 4 0x7FF7950445C0 lua_pcall <unknown>:0
ERROR:CRASH: 5 0x7FF795076170 dmScript::PCallInternal D:\a\defold\defold\engine\script\src\script.cpp:1386
ERROR:CRASH: 6 0x7FF7950C2810 dmGameObject::RunScript D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:138
ERROR:CRASH: 7 0x7FF7950C2A00 dmGameObject::CompScriptUpdateInternal D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:236
ERROR:CRASH: 8 0x7FF79509FA60 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2632
ERROR:CRASH: 9 0x7FF79515C2E0 dmGameSystem::CompCollectionProxyUpdate D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_collection_proxy.cpp:299
ERROR:CRASH: 10 0x7FF79509FA60 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2572
ERROR:CRASH: 11 0x7FF795114540 dmEngine::StepFrame D:\a\defold\defold\engine\engine\src\engine.cpp:1570
ERROR:CRASH: 12 0x7FF79510F770 dmEngineUpdate D:\a\defold\defold\engine\engine\src\engine.cpp:2098
ERROR:CRASH: 13 0x7FF795114F60 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:83
ERROR:CRASH: 14 0x7FF79503AEB0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:148
ERROR:CRASH: 15 0x7FF7953463F4 __scrt_common_main_seh d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
ERROR:CRASH: 16 0x7FFB210F7600 BaseThreadInitThunk <unknown>:0
ERROR:CRASH: 17 0x7FFB21742680 RtlUserThreadStart <unknown>:0
ERROR:CRASH: Lua Callstack:
ERROR:CRASH: [C]:-1: in function mesh_set_aabb
ERROR:CRASH: world/game/levels/level_creator.lua:389: in function init_meshes
ERROR:CRASH: world/game/levels/level_creator.lua:258: in function <world/game/levels/level_creator.lua:150>
ERROR:CRASH:
INFO:CRASH: Successfully wrote MiniDump to file: C:\Users\user\AppData\Roaming\Defold/_crash.dmp
local res = go.get(mesh_id, "vertices")
local buffer = resource.get_buffer(res)
pprint(res)
pprint(buffer)
game.mesh_set_aabb(buffer)
static int MeshSetAABB(lua_State *L) {
DM_LUA_STACK_CHECK(L, 0);
d954masGameUtils::check_arg_count(L, 1);
dmBuffer::HBuffer mesh = dmScript::CheckBuffer(L, 1)->m_Buffer;
dmBuffer::Result validate = dmBuffer::ValidateBuffer(mesh);
if(validate!=dmBuffer::RESULT_OK ){
luaL_error(L,"buffer invalid");
}
float* positions = 0x0;
uint32_t size = 0;
uint32_t components = 0;
uint32_t stride = 0;
uint32_t count = 0;
dmBuffer::Result r = dmBuffer::GetStream(mesh, dmHashString64("position"), (void**)&positions, &count, &components, &stride);
if (r == dmBuffer::RESULT_OK) {
//must have at least 1 point
if(size>0 && false){
float aabb[6];
//min
aabb[0] = positions[0];
aabb[1] = positions[1];
aabb[2] = positions[2];
//max
aabb[3] = positions[0];
aabb[4] = positions[1];
aabb[5] = positions[2];
positions += stride;
for (int i = 1; i < count; ++i){
float x = positions[0];
float y = positions[1];
float z = positions[2];
if(x<aabb[0]) aabb[0] = x;
if(y<aabb[1]) aabb[1] = y;
if(z<aabb[2]) aabb[2] = z;
if(x>aabb[3]) aabb[3] = x;
if(y>aabb[4]) aabb[4] = y;
if(z>aabb[5]) aabb[5] = z;
positions += stride;
}
dmBuffer::Result metaDataResult = dmBuffer::SetMetaData(mesh, dmHashString64("AABB"), &aabb, 6, dmBuffer::VALUE_TYPE_FLOAT32);
if (metaDataResult != dmBuffer::RESULT_OK) {
luaL_error(L,"dmBuffer can't set AABB metadata");
}
}
} else {
luaL_error(L,"dmBuffer can't get position.Error:%d",r);
}
return 0;
}
If you get the buffer from a resource you can’t use the m_Buffer pointer as-is, you need to get it from the m_BufferRes. @JCash maybe we need to expose the UnpackLuaBuffer function to the dmsdk?
If checkbuffer isn’t enough, then yes we need to do some changes.
Yes this buffer is from mesh component.(.buffer file)
dmScript::LuaHBuffer* buffer = dmScript::CheckBuffer(L, 1);
dmLogInfo("Owner:%d",buffer->m_Owner);
Owner:2