jeske / SimpleScene

Simple 3D scene manager in C# and OpenTK / OpenGL
https://github.com/jeske/SimpleScene/wiki
Other
171 stars 69 forks source link

Change texture on loaded meshs #17

Closed eXponenta closed 8 years ago

eXponenta commented 8 years ago

How change texture on OBJ or md5 meshs? Changing Mesh.textureMaterial or Object.textureMaterial does not work. After loading and instancing mesh on scene _.texture Material _always NULL.

HoneyHazard commented 8 years ago

Currently we have things like this: mesh texture material, when not null, overrides object texture material. Geometry subset texture material, when not null, overrides mesh texture material. However, geometry subsets were not publically accessible leaving you with no way to change the textures. I've made this variable public just now and did a similar thing for skeletal submeshes. See this commit https://github.com/jeske/SimpleScene/commit/37234bba464f877fb4698807be86b059f636cdc8

You can now assign submesh textures like this:

var asWf = droneObj1.Mesh as SSMesh_wfOBJ; var tex = SSAssetManager.GetInstance<SSTexture> ("checkerboard.png"); var texMat = new SSTextureMaterial (diffuse: tex); foreach (var subset in asWf.geometrySubsets) { subset.TextureMaterial = texMat; }

I can see how this is non-ideal because it overrides texture on ALL instances of the mesh. We will have to think on how to implement in otherwise, but I hope it will not be stopping you from doing what you are doing in the meantime.

screenshot_2016-04-11_09-24-31

jeske commented 8 years ago

Keep in mind, that even if you set a different texture, the UV coordinates are still being drawn from the OBJ file. This means the UV layout of your texture needs to match the UV layout exported with the OBJ file.

If you wish to use a different UV layout, you'll need to load the OBJ into a program like blender, change the UV layout, and re-export.

At some point it might make sense to include simple programmatic UV layouts just for basic code experimentation, such as cylindrical, spherical, cubemap, etc. These are not usually useful in practice, so they havn't been added yet.

On Mon, Apr 11, 2016 at 9:29 AM, HoneyHazard notifications@github.com wrote:

Currently we have things like this: mesh texture material, when not null, overrides object texture material. Geometry subset texture material, when not null, overrides mesh texture material. However, geometry subsets were not publically accessible leaving you with no way to change the textures. I've made this variable public just now and did a similar thing for skeletal submeshes. See this commit 37234bb https://github.com/jeske/SimpleScene/commit/37234bba464f877fb4698807be86b059f636cdc8

You can now assign submesh textures like this:

var asWf = droneObj1.Mesh as SSMesh_wfOBJ; var tex = SSAssetManager.GetInstance ("checkerboard.png"); var texMat = new SSTextureMaterial (diffuse: tex); foreach (var subset in asWf.geometrySubsets) { subset.TextureMaterial = texMat; }

I can see how this is non-ideal because it overrides texture on ALL instances of the mesh. We will have to think on how to implement in otherwise, but I hope it will not be stopping you from doing what you are doing in the meantime.

[image: screenshot_2016-04-11_09-24-31] https://cloud.githubusercontent.com/assets/8847050/14434368/3d38559a-ffc7-11e5-8275-e3a75f4f493f.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/jeske/SimpleScene/issues/17#issuecomment-208435351

eXponenta commented 8 years ago

Thanks!