smart-fun / smartGL

SmartGL is a Graphic Engine for creating Android Games and Apps. It is based on OpenGL and handles 2D Sprites and 3D Textured Objects.
Apache License 2.0
109 stars 24 forks source link

java.lang.RuntimeException: Model must have texture UVs or vertex Colors #19

Closed jehadmashhour closed 5 years ago

jehadmashhour commented 5 years ago

I'm trying to show my 3d model by using your library but the model doesn't show , always i get error is java.lang.RuntimeException: Model must have texture UVs or vertex Colors , i have tried the solutions here https://github.com/smart-fun/smartGL/issues/12 but i still get the same error .

Some solutions i have tested : 1 - exporting the same model with blender with ticking the "Triangulate Faces" option . 2 - exporting the same model with MeshLab .

But to no avail.

earthblender.zip

smart-fun commented 5 years ago

Hello and thank you for using smartGL :)

I can see 2 compatibility issues between your object and the library:

regarding the "multiple objects" in the file, I didn't know it was possible, and it could be a great improvement for the library. I'll keep the idea :) but it won't be fixed today.

regarding the "no property" issue, for the moment I have no idea what should be done. Display a fully white object ? The objects are supposed to have colors or picture.

Arnaud.

smart-fun commented 5 years ago

I had a deeper look to the problem.

please upgrade to version 1.1.9 and if you look at the new documentation, I have added:

Note that if your Model does not have a texture but colors on each vertex, you'll have to use a specific "color" shader instead of the default one:

new RenderPassObject3D(RenderPassObject3D.ShaderType.SHADER_COLOR, true, true);

Also if there are no textures and no colors on vertex, you can specify a default color in the WavefrontModel.Builder using:

builder.setColor(0.5f, 0.3, 0.8f); // RGB

In the future I think I will merge all shaders and the model could have textures and/or colors and/or a default color.

Please tell me if your model loads correctly.

Also can I use your model in the sample app so that I have an example without a texture and without colors ?

thanks,

Arnaud.

jehadmashhour commented 5 years ago

Thanks for ur answer , there is no problem to use my 3d model and this's will be appreciated .

Yes now i understand why my 3d model doesn't work so that i went to the blender to generate UVs which means vt in the obj file .

To help developers : by using blender u can do that by doing these steps :

Minimal example to include texture coordinates / vt in OBJ format: File -> New Change from Object Mode to Edit Mode Click Shading / UVs from the upper left vertical aligned tabs Under UV Mapping, change from Unwrap to Cube Projection under Export to OBJ Conclusion: The key to include vt in OBJ is step 4. Step 4 is only available in Edit Mode.

Thanks for the new addition in the latest version that's really helpful .

The problem that i faced as a developer (not designer) is how to generate a 3d model with it's vertex colors , as u see my 3d model has a colors included as a materials , so how i can change them to be vertex colors , i still struggle with that to do it by using Blender or MeshLab , so plz if u have a hint (help) for a steps then this's will be appreciated ??

However , I find another solution to handle the colors of my materials to show them as a textures by using this way : 1 - Generate my 3d model by using Blender with including UVs (vt) as the steps i mentioned them at the top .

2 - Handle the colors as a textures by doing this code : Texture Red = createTexture(Color.parseColor("#D11500"), Color.parseColor("#D11500")); Texture White = createTexture(Color.parseColor("#D1D1D1"), Color.parseColor("#D1D1D1")); Texture LightBrown = createTexture(Color.parseColor("#7B513E"), Color.parseColor("#7B513E")); Texture Green = createTexture(Color.parseColor("#2A821E"), Color.parseColor("#2A821E")); Texture Brown = createTexture(Color.parseColor("#492F1E"), Color.parseColor("#492F1E")); Texture DarkGreen = createTexture(Color.parseColor("#216519"), Color.parseColor("#216519")); Texture Blue = createTexture(Color.parseColor("#4F96A5"), Color.parseColor("#4F96A5")); Texture Snow = createTexture(Color.parseColor("#BDBDBD"), Color.parseColor("#BDBDBD"));

private Texture createTexture(int colorBg, int colorDetails) { int tx = 3; Bitmap bitmap = Bitmap.createBitmap(tx + 1, tx + 1, Bitmap.Config.ARGB_8888); bitmap.eraseColor(colorBg); // Закрашиваем цветом bitmap.setPixel(0, 0, colorDetails); bitmap.setPixel(0, tx, colorDetails); bitmap.setPixel(tx, 0, colorDetails); bitmap.setPixel(tx, tx, colorDetails); Texture texture = new Texture(tx, tx, bitmap); return texture; }

3 - load it by the following method code :

private Object3D loadEarth(@NonNull Context context, Texture Red, Texture White, Texture LightBrown , Texture Green, Texture Brown, Texture DarkGreen, Texture Blue, Texture Snow) { WavefrontModel model = new WavefrontModel.Builder(context, R.raw.earthblender) .optimize(true) .addTexture("Red", Red) .addTexture("White", White) .addTexture("LightBrown", LightBrown) .addTexture("Green", Green) .addTexture("Brown", Brown) .addTexture("DarkGreen", DarkGreen) .addTexture("Blue", Blue) .addTexture("Snow", Snow) .create(); Object3D object3D = model.toObject3D(); object3D.setScale(10f, 10f, 10f); object3D.setPos(0, 0, -50); return object3D; }

The result as a colors showing as a textures :

screenshot_2018-12-05-17-45-39

smart-fun commented 5 years ago

I have made a new build 1.2.0 with a new shader (SHADER_COLOR_LIGHTS), and your planet has been added to the sample app. So even without textures it is possible to display an object and define a color.

image

give a try to the sample app ;)

Arnaud.