Multiple materials per model

About Monkey 2 Forums Monkey 2 Programming Help Multiple materials per model

This topic contains 3 replies, has 2 voices, and was last updated by  Hezkore 1 year, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9160

    Hezkore
    Participant

    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?

    #9161

    Mark Sibly
    Keymaster

    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:

    #9162

    Mark Sibly
    Keymaster

    …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.

    #9163

    Hezkore
    Participant

    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())

    Anyways, thanks!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.