Class Model
A 3D mesh placed in the world: a com.codename1.gpu.Mesh plus a
com.codename1.gpu.Material and a position / rotation / scale transform. Add one
to a GameView (GameView#addModel(Model)) to draw it in the perspective camera
alongside the billboarded sprites.
Because GPU meshes need the com.codename1.gpu.GraphicsDevice to be created, build
your models from inside GameView#onSetup(com.codename1.gpu.GraphicsDevice):
protected void onSetup(GraphicsDevice device) {
Mesh cubeMesh = Primitives.cube(device, 1f);
Material gold = new Material(Material.Type.PHONG).setColor(0xffffcc33).setShininess(32);
Model crate = new Model(cubeMesh, gold);
crate.setPosition(0, 0.5f, 0);
addModel(crate);
}
Rotation is applied in Z, then Y, then X (extrinsic), in degrees. The model is
drawn with the GameView's shared com.codename1.gpu.Light, so lit material
types (com.codename1.gpu.Material.Type#LAMBERT/#PHONG) are shaded by it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns how many copiessetInstancesasked for, 0 for a single model.getMesh()floatfloatfloatfloatgetX()floatgetY()floatgetZ()booleansetInstances(float[] matrices, int[] colors, int count) Draws this model as many copies, each placed by its own transform relative to the model's position, rotation and scale: a stack of crates, a row of lamp posts, a field of grass from one blade.voidsetMaterial(Material material) voidsetPosition(float x, float y, float z) setRotation(float degX, float degY, float degZ) Sets the Euler rotation in degrees (applied Z, then Y, then X).setScale(float scale) setScale(float scaleX, float scaleY, float scaleZ) voidsetUserData(Object userData) voidsetVisible(boolean visible)
-
Constructor Details
-
Model
Creates a model for the given mesh with a default unlit white material. -
Model
-
-
Method Details
-
getMesh
-
setMesh
-
getMaterial
-
setMaterial
-
getX
public float getX() -
getY
public float getY() -
getZ
public float getZ() -
setPosition
-
setRotation
Sets the Euler rotation in degrees (applied Z, then Y, then X). -
getRotationX
public float getRotationX() -
getRotationY
public float getRotationY() -
getRotationZ
public float getRotationZ() -
setScale
-
setScale
-
isVisible
public boolean isVisible() -
setVisible
public void setVisible(boolean visible) -
getUserData
-
setUserData
-
setInstances
Draws this model as many copies, each placed by its own transform relative to the model's position, rotation and scale: a stack of crates, a row of lamp posts, a field of grass from one blade. The arrays are read every frame, so moving the copies is writing new values into them; they are not copied.
Parameters
-
matrices: 16 column-major floats per copy, or null to draw the model once again -
colors: an ARGB colour per copy forShaderNode.instanceColor, or null for white -
count: how many copies to draw
Returns
this model
-
-
getInstanceCount
public int getInstanceCount()Returns how many copiessetInstancesasked for, 0 for a single model.
-