How to use addMeshObject()? [SOLVED]

I’m trying to figure out how to use addMeshObject() to add an object to my scene with an existing mesh.
The problem is that I don’t know what to put on the materials parameter, since it requires Vector instead of the MaterialData that I have. After looking around for a while I figured out I could get a Vector using Vector.fromData(), but I don’t know how to get the _Vector.VectorData<Unknown<0>> needed for this method.

Also, since I’m unexperienced at coding, I would like to know how could I figure stuff like this by myself, since there isn’t documentation on it, the only example I could find that used addMeshObject (generate mesh) didn’t explain it and didn’t use an existing mesh so it’s different; and by looking at the code directly It seems like a botomless pit since to understand the definition I will need to figure out another function or another type…

Thanks for your patience.

Hi,

the material parameter requires a Vector of MaterialData (Vectors can be used like arrays), you could write for example:

import haxe.ds.Vector;

var matData: MaterialData = ...;

// Create a new Vector with length 1
var materials: Vector<MaterialData> = new Vector(1);
materials[0] = matData;

// Alternative you described, creates a new Vector from the given array
var materials: Vector<MaterialData> = Vector.fromData([matData]);

Here you can find the definition of addMeshObject(): https://github.com/armory3d/iron/blob/cb175d4cd1402f3c0cf41f42a8d3302ed8e6a46b/Sources/iron/Scene.hx#L304

If you want some examples, have a look at those: https://github.com/search?l=Haxe&q=org%3Aarmory3d+addMeshObject&type=Code

4 Likes

Many thanks, I wasn’t familiar with the use of vectors as arrays, I also didn’t know you could search for specific snippets of code on github, that will be very useful.

1 Like