jeske / SimpleScene

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

Ability to change mesh's texture? #19

Open blendogames opened 7 years ago

blendogames commented 7 years ago

I was looking for a way to change an SSObjectMesh's texture while the program is running. My attempt at it was:

myObjectMesh.textureMaterial = new SSTextureMaterial (myNewTexture);

However, this doesn't seem to do anything -- I'm guessing I'm misunderstanding how SimpleScene handles this, looking for any suggestions! Thanks.

jeske commented 7 years ago

What type of mesh is it?

If your object is loaded from wavefront OBJ/MTL files, then you need to look at "SSMesh_wfOBJ". Because wavefront supports multiple textures in an object, it doesn't use AbstractMesh.textureMaterial. Instead it has it's own "material subsets", each with a mesh and texture. You'll have to find the right one in the list (SSMesh_wfOBJ.geometrySubsets) and reassign it.

blendogames commented 7 years ago

Thank you, this clears a lot of things up for me. I'm now able to swap new textures onto my existing mesh objects with the following code.

SSTexture myNewTexture = SSAssetManager.GetInstance<SSTextureWithAlpha>("./newtexture.png");

SSMesh_wfOBJ myInstance = SSAssetManager.GetInstance<SSMesh_wfOBJ>("./modelfile.obj");
myInstance.geometrySubsets[0].textureMaterial = new SSTextureMaterial(myNewTexture);

myMeshObject = new SSObjectMesh(myInstance);