Instantiating planes from code


#1

I know I can wrap a plane in a symbol and use the Z.Symbol constructor to instantiate the symbol with the plane I want to use. But is there a way to instantiate a plane directly without needing to wrap it in a symbol? Pretty much like you can do with fonts using the Z.Font constructor.


#2

If you drag a plane into the hierarchy you actually just get a Z.Object node with it’s type property set to “plane”.

So the equivalent in code is just to create an Object node as Z.Object() and then set the type property to the plane object in the media files list. You can chain the two together too:
var myNewPlane = Z.Object().type(symbol.mediaFiles.Plane);


#3

To be more explicit the “type” parameter of an Object node is actually a Z.ObjectType object. You can construct that manually as Z.ObjectType(symbol.mediaFiles.plane), but there is no need to do so, if you pass a string into the object node’s type setter it will do that for you.

The same is true of the ‘font’ property of Z.Text nodes by the way - you don’t need to make your own Z.Font object, you can just pass the media file reference instead, eg myTextNode.font(symbol.mediaFiles.fontfile);


#4

Thanks Simon!