We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding Materials To 3D Model


I have followed your examples and am trying to add a material to a 3d cube.

The code creates the cube and seemingly the UV points etc, but when trying to view the cube the render is throwing an error:

‘An unhandled exception of type ‘System.IndexOutOfRangeException’ occurred in Aspose.3D.dll’

at Aspose.ThreeD.Utilities.Vertex.#=q5yGdFc38ReZ1ySTSBHow5w==(VertexField #=q_rnsaTgP$Eg2AfyDFTt4tA==, VertexElement #=qh06f6GDuEnn67OJR7pJQlg==, Int32 #=qBH2et18RN$T1mEVTTHivXQ==)
at Aspose.ThreeD.Entities.TriMesh.#=qTRcQ0MoAsFXeHoJIJOoMz7za9Zy1h7LYy1f37ZQSZ0M=(TriMesh #=qUS9ooLXeZF2pvZZLmiUZkw==, Mesh #=qN2DDytfn5ImtdG1$f7r27g==, #=q1wcp2NaOfzkVba3dLS0LVqYLKhm4FyJpvLRChQk$KOsTS_Wf7j65o6yzYhfjC5nu #=qWREFv5lhMYqXL9rI92O33RBeRmwFE3$c9939dcmEeDk=)
at #=qEGKtkbuQxdZ1DVrAgSs8F$ulqBVbBFQF5qSInw3v4YY$mj_F83z9$4I8HtSHby53.#=qe9S509aoZFKOOq8dksuznQ==(Mesh #=qAY2BG5CwYhQHegUtu09$uQ==)
at #=qEGKtkbuQxdZ1DVrAgSs8F$ulqBVbBFQF5qSInw3v4YY$mj_F83z9$4I8HtSHby53.#=qyWvHXN3AWisB$EuHQVk1Rw==()
at #=qEGKtkbuQxdZ1DVrAgSs8F$ulqBVbBFQF5qSInw3v4YY$mj_F83z9$4I8HtSHby53…ctor(Node #=qEvxtcoYy2mprButGHmvYiw==, Mesh #=qN2DDytfn5ImtdG1$f7r27g==)
at Aspose.ThreeD.Entities.Mesh.CreateRenderableResource(Renderer renderer, Node node)
at Aspose.ThreeD.Render.Renderer.#=qFw8DuU$I3CBhkpUzd9M1TuT7ZXGcL$y5rpgLc2pjh5E=(Node #=qEvxtcoYy2mprButGHmvYiw==, Entity #=qgQPlRGg$p_cTLqk5EWi87A==)
at Aspose.ThreeD.Render.Renderer.#=qWrsFVCwv26gB2FdtgkM9jA==(Node #=qEvxtcoYy2mprButGHmvYiw==)
at Aspose.ThreeD.Render.Renderer.#=qWrsFVCwv26gB2FdtgkM9jA==(Node #=qEvxtcoYy2mprButGHmvYiw==)
at Aspose.ThreeD.Render.Renderer.#=qqZGHWTbvN7VusGyeP_cmllYVmlJZmV_VetmieSEMdZo=()
at Aspose.ThreeD.Render.Renderer.#=qvjf1m0QaYbMKngjOebAIUFV1Ri16RtgRGLj8it0RWQI=(#=qOPpVAOEbgabM62pwB_FxjHpWll5105QL5nl4FHuEYvhZqN7uajLJ2CGNm16WJl5X #=qsiuFAx2AEgu$PBD42tqmtQ==)
at Aspose.ThreeD.Render.Renderer.Render(IRenderTarget renderTarget)
at CityBuilder.Controls.RenderView.OnPaint(PaintEventArgs e) in C:\work\my\Roblox\CityBuilder\Controls\RenderView.cs:line 138
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Do you have any idea where i’m going wrong ?


Sorry, I worked this out, its working now.

Another question, can I apply a material directly to a polygon ?

There is no way to apply material over a Polygon. We have logged an investigation under the ticket ID THREEDNET-278 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience.

Best Regards,
Imran Rafique

Thank you for being patient. The Node class has a “Materials” property which allows to specify more than one material, then using the VertexElementMaterial class, we can specify the index to each material per polygon. The following code example demonstrates how to share a mesh under multiple nodes and with different materials:


Scene scene = new Scene();
//the box has 6 faces, we'll give it 2 materials
Mesh mesh = (new Box()).ToMesh();
//create a VertexElementMaterial to describe the material per polygon
var mat = (VertexElementMaterial) mesh.CreateElement(VertexElementType.Material, MappingMode.Polygon, ReferenceMode.Index);
// the 0/2/4-th face will use the 0th material and 1/3/5-th face will use the 1st material
mat.Indices.AddRange(new int[]{0, 1, 0, 1, 0, 1});

//now we create 10 nodes to hold this mesh
Random r = new Random();
for (int i = 0; i < 10; i++)
    var node = scene.RootNode.CreateChildNode(mesh);
    //give them enough space
    node.Transform.Translation = new Vector3(i * 5, 0, 0);
    node.Transform.Rotation = Quaternion.FromEulerAngle(i / 0.001, i / 0.03, 0);
    //each node has 2 materials which will be used by the mesh
    for (int j = 0; j < 2; j++)
        LambertMaterial lambert = new LambertMaterial();
        //and have random color
        lambert.DiffuseColor =  new Vector3(r.NextDouble(), r.NextDouble(), r.NextDouble());
//save it to FBX file
scene.Save(@"C:\temp\instancing.fbx", FileFormat.FBX7400ASCII);

PS: the ticket ID THREEDNET-278 has been closed.

Best Regards,
Imran Rafique