neumond / blender-md3

.md3 models support for Blender
MIT License
62 stars 23 forks source link

Vertices count #8

Closed mino-git closed 7 years ago

mino-git commented 7 years ago

Hello neumond,

i once wrote about this but got no answer. Basically, your script produces new and unneeded vertices.

Example: make a simple cube with all the settings needed, then export, then import again into Blender. You will see the vertex count trippled.

The core problem is, that md3, as well as mdc, for which i wrote a plugin right now, needs each vertex to be mapped exactly once to the uv map.

I wrote a script, as i said above, for the mdc file format. Check this here: https://github.com/acqu/wet-blender-mdc/commit/55cf892135dd2cf8689d8b511fa8c258eea3308e

I hope this helps, and you can integrate this code, cause sometimes i hit a max vertices count with your import/export script, and generally i think this vertex growth is too much and it seems random. Can you explain why you do this? Or if it really matters? Would be interested on your opinion. Cheers.

neumond commented 7 years ago

Hello @acqu

Yes, vertex duplication is kinda by design. Speaking more strictly, it's a requirement of .md3 format: every vertex can have only one texcoord. With cube example, vertices have 3 texcoords for every plane they share. Script has to duplicate vertex coordinates to be able to export texcoords correctly.

When you import, it takes vertices "as is", so you can weld them in blender if you want. Probably I can weld them automatically on import. Need to take a look here.

Regarding max vertices, it's merely a warning, since the specification defines some limits. If your game engine supports more vertices - just feel free to overcome these limits.

mino-git commented 7 years ago

Yes, vertex duplication is kinda by design.

Gimme a day, i will comment here again. I already wrote a comment, but i noticed you do flat shading with the vertex duplication. During smooth the models work, but not the uvmap. Will do some more checking.

Here check this: test3.zip

Basically, the old smooth shading problem? On this cube, when i use the md3 script and have smooth shading enabled, the uv map does not export. Am i right? It says "zero filling" or something. The mdc script on the other hand creates 6 new vertices with averaged out normals.

Had always been using the Flat shading option during .md3. Did not think it would make a difference.

neumond commented 7 years ago

Unique key for vertex currently is (position, normal, texcoords) https://github.com/neumond/blender-md3/blob/master/io_scene_md3/export_md3.py#L73 It should split vertices correctly now, for any combination of parameters.

mino-git commented 7 years ago

So i checked now repeatedly and it does not work on models with certain uv maps.

Check the test4.zip here: test4.zip

This model is set to smooth shading, and the uv map has a t-shape (important). Export with md3 export option, then import again. No vertices will be duplicated, and all uv map coords will be set to 0. The result should be a total of 14 vertices and the same uv map.

I am only able to provide very smelly code and it needs to get tested even more (have done already alot), but it seems it works now. Check this function here called readUVMap to see how i do it in mdc. https://github.com/acqu/wet-blender-mdc/blob/fb4b12238934dfd1bbe8032b0c824502bf4797d1/io_scene_mdc/mdc_modules/blender_scene.py#L51

Note: when you set this cube from above to flat shading, it will correctly export the uv map, and vertices will also be correctly exported.

neumond commented 7 years ago

Give me some time, too busy with other things.

mino-git commented 7 years ago

Ok, no problem. Glad you replied and keep this updated :)

neumond commented 7 years ago

test3.zip

I don't see any UV map generated for the model. You have to create it first, then export as md3.

neumond commented 7 years ago

test4.zip

Don't forget to activate UVMap in your material. screenshot 2017-09-22 18 05 39

neumond commented 7 years ago

I also had problem with revealing imported UVMap: don't forget to select proper scene after switching to UV Editing mode. The mesh after export-import process is auto-triangulated: screenshot 2017-09-22 18 44 04

mino-git commented 7 years ago

Ah, the missing UV mapping confused me. It worked before with flat shading enabled. Smooth shading and flat shading are implicit, i kinda wished it was explicit in some kind of export menu. Well. Thanks and it now works.

neumond commented 7 years ago

Yea, smooth and flat shadings are exactly as in blender scene. You can export mixed flat/smooth models, e.g. some rounded corner geometry with sharp edges and smooth spherical surfaces. This would be impossible in case of export menu option control.

mino-git commented 7 years ago

I see. Thanks for taking the time.