axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
923 stars 205 forks source link

Loading a material on a 3D MeshRenderer model confuses rendering #1048

Closed TedGriggs closed 1 year ago

TedGriggs commented 1 year ago

When you setMaterial() on a 3D mesh, its rendering is tweaked and animations do not work.

We've modified the basic HelloWorldScene to demonstrate.

It loads a model "orc.c3t" (from the ccptests), gives it a plain texture, ("Yellow.png" - a 16x16 solid yellow image which just colors the orc entirely yellow), and starts an animation. This draws and animates the orc correctly.

It also loads a second "orc.c3t" model and gives it a simple material, "orc.material", that uses the most minimal shader you can do (just paint every pixel white, see "orc.vert" and "orc.frag"). It does not draw the orc correctly and it does not animate.

Using setPosition(), setRotation(), and setScale(), you can move the second orc around. It seems like no transforms are being applied to the meshes, bones, or whatever make up the second orc.

I bundled everything into a zip file. issue.zip

Maybe there is a misunderstanding on how materials are supposed to work. In any case, hopefully someone is still working on this engine that can take a look!

TedGriggs commented 1 year ago

Hi! Just following up on this issue. If you're not interested in reproducing this with the code I provided, can you point to an example of where you set a material (via setMaterial() not setTexture()) on a 3D mesh and have it animate properly.

Thanks!

halx99 commented 1 year ago

The material seems incorrect for draw 3d mesh

TedGriggs commented 1 year ago

What does that mean? Can you point me to a material for a 3d mesh that uses a shader that is "correct" and animates?

solan-solan commented 1 year ago

To create your own material for your objects look pls these shaders as reference:

axmol-dir\cocos2d\core\renderer\shaders\3D_positionNormalTexture.vert
axmol-dir\cocos2d\core\renderer\shaders\3D_colorNormalTexture.frag

or

axmol-dir\cocos2d\tests\cpp-tests\Resources\Shaders3D\3d_position_skin_tex.vert (no normal attribute)
axmol-dir\cocos2d\tests\cpp-tests\Resources\Shaders3D\3d_color_tex.frag

or other combinations.

TedGriggs commented 1 year ago

Okay, I see what I need to do now. The getPosition() in the vertex shader was the key. Thanks!