I’m generating my own meshes from an external file, and I want to have a bunch of different textures for that mesh.
In MiniB3D I would create different surfaces for that mesh and apply textures to those surfaces.
Is there something similar in Mojo3D?
Use Mesh.AddMaterials( count:Int ) to add materials to a mesh, and use the ‘materialid’ parameter (defaults to 0) of Mesh.AddTriangles() to add triangles to a particular material.
A mesh starts with one material (with id=0), so first material you add will have id=1, next will have id=2 etc.
But meshes don’t actually store physical material instances, just the triangles assigned to each material ‘id’. Materials are actually stored in the Model entity (that also stores the mesh) via the Model.Materials property.
So the basic idea is:
Monkey
1
2
3
4
5
6
7
8
9
10
11
12
Localmesh:=NewMesh
Mesh.AddVertices(...)'vertices
mesh.AddMaterials(3)'mesh now has 4 materials (starts with 1).
Mesh.AddTriangles(...,0)'add triangles to material 0
Mesh.AddTriangles(...,1)'add triangles to material 1
Mesh.AddTriangles(...,2)'add triangles to material 2
Mesh.AddTriangles(...,3)'add triangles to material 3
…also, each Model has a ‘default material’ property called Model.Material. This is used if there aren’t enough materials in the model’s Materials array to render the mesh with, so is very convenient if you just want to render a mesh with a single material etc, ie: just use Model.Material instead of Model.Materials.
Ah mesh had those functions, very nice… totally missed that. (shame on me)
I only looked at the Mesh Extension code and used New Mesh(vertices.ToArray(),triangles.ToArray())