Project with 3D models

Hi
I’m trying to add a 3D model to my project, like here: http://www.defold.com/manuals/model/ . But I just can’t set it up right, the model is not visible no matter what I try. I’m new to game programming, so it’s hard to figure out what I’m doing wrong.
Maybe someone could share a basic project with 3D model? It would be a great help for the beginners.

4 Likes

It would be nice if that Book of Defold project was downloadable.

2 Likes

I found this quite tricky myself, and have not been able to render a 3D model successfully. So sadly I can not provide you with any project. But nonetheless, I can direct you to the relevant defold documentations to, hopefully, help you along the way.

Since there is no built-in material suitable for 3D rendering in Defold you have to create your own custom one. The custom material is necessary in order for the renderer to render the 3D object correctly. A material consists of three files: a vertex shader (.vp), a fragment shader (.fp), and a material file (.material). You can find documentation of this here: Documentation of materials

You also need to alter the rendering script to be able to render 3D objects properly, since the rendering pipeline is set up for 2D rendering. You can find documentation of rendering here: Documentation of rendering

I am by no means an expert, so feel free to correct me if I am wrong.
Hope this helps in somehow!

3 Likes

Hi all! Didn’t have a proper computer for the whole weekend, so sorry for the late reply! :slight_smile:

I threw together an extremely simple 3D project, it includes;

  • gameobject with a model component using a collada file
  • material for 3D, attached to the model component
  • render_script that only renders the 3D-tags/-predicates

SvensSimple3DProject.zip

I added some simple input handling to the gameobject as well.
Hope this helps to get things started! :smiley:

10 Likes

Thanks a ton! Now everything is clear enough.

3 Likes

Here are the assets for Book of Defold. I just zipped the content of that folder from the project. Hope it’s helpful.

model_example.zip (1.6 MB)

5 Likes

Thank you!

Does it rely on anything different in the render script that is not in the zip? I’ve tried merge the example from sven with it, but can’t get book to display. Even tried remaking parts again.

The book model is a bit bigger than my cube, change the camera position to compensate for this (in main.render_script):

local cam_pos = vmath.vector3(0.0,0.0,20.0)

then just change the mesh resource so it points to book_of_defold.dae;

Results in:

2 Likes

Great! It’s working!

I did resize it down before, but I also changed the material to the textured.material which was included in the book example, and even with the camera position set back a bit with the textured.material it still does not show up. There are several differences between the materials.

What to do if UVs do not appear to be working? I have a dae model which was exported from Qubicle (I PMed you a sample), and its UVs are not appearing to be correct. I have tried to change some of the material settings for UVs but none of them change it.

1 Like

I’ll have a quick look at this! Could be a bug, or something we don’t currently support, in our Collada importer.

edit:
This seems to be the result of a really old issue; DEF-787, “Imported Collada-file meshes gets UV map Y-inverted”. :slight_smile:

To solve this I changed my vertex shader to:

...
var_texcoord0 = vec2(texcoord0.s, 1.0 - texcoord0.t);
...
3 Likes

Awesome! Working! :grin:

2 Likes

Yeah, that’s an old one. I inverted the texture of the book in the example project for that reason. Maybe bump that issue? :slight_smile:

3 Likes

Can anybody help? Many options tried, but always my model is not visible at compile time, I expect that the textures are not borne by the model. To do everything by the book
http://hostingkartinok.com/show-image.php?id=7e89020b86832b10fb7e9dff52126eea

Upload a zip of what you have so far. Maybe you didn’t set the material correctly? Also, textures won’t show up in the current editor.

I doubt that a mistake in configuring
material.To my problem may be involved in the topic “Rendering”? missing file or an incorrect code of the script? or even without these things in the editor should not be white cubes? Even without looking at the compile step

http://hostingkartinok.com/show-image.php?id=3295ef041fbb3ff9f786f38d824ba41b

strange that I used above attached - SvensSimple3DProject.zip and it works

relax guys, I still will understand itself to working SvensSimple3DProject.zip

2 Likes

Hi!
Have you the same but with samplerCube ?