public class Model
- Object
- 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.
Constructors
public Model(Mesh mesh) | Creates a model for the given mesh with a default unlit white material. |
public Model(Mesh mesh, Material material) | Creates a model for the given mesh and material. |
Methods
Inherited methods
Constructor details
Model
public Model(Mesh mesh)Creates a model for the given mesh with a default unlit white material.
Model
public Model(Mesh mesh, Material material)Creates a model for the given mesh and material.
Method details
getMesh
public Mesh getMesh()setMesh
public void setMesh(Mesh mesh)getMaterial
public Material getMaterial()setMaterial
public void setMaterial(Material material)getX
public float getX()getY
public float getY()getZ
public float getZ()setPosition
public Model setPosition(float x, float y, float z)setRotation
public Model setRotation(float degX, float degY, float degZ)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
public Model setScale(float scale)setScale
public Model setScale(float scaleX, float scaleY, float scaleZ)isVisible
public boolean isVisible()setVisible
public void setVisible(boolean visible)getUserData
public Object getUserData()setUserData
public void setUserData(Object userData)