Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class Model

  1. Object
  2. 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

public Mesh getMesh()
public void setMesh(Mesh mesh)
public Material getMaterial()
public void setMaterial(Material material)
public float getX()
public float getY()
public float getZ()
public Model setPosition(float x, float y, float z)
public Model setRotation(float degX, float degY, float degZ)Sets the Euler rotation in degrees (applied Z, then Y, then X).
public float getRotationX()
public float getRotationY()
public float getRotationZ()
public Model setScale(float scale)
public Model setScale(float scaleX, float scaleY, float scaleZ)
public boolean isVisible()
public void setVisible(boolean visible)
public Object getUserData()
public void setUserData(Object userData)
public Model setInstances(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.
public int getInstanceCount()Returns how many copies setInstances asked for, 0 for a single model.

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)

setInstances

public Model setInstances(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. The arrays are read every frame, so moving the copies is writing new values into them; they are not copied.

Parameters

matrices float[]
16 column-major floats per copy, or null to draw the model once again
colors int[]
an ARGB colour per copy for ShaderNode.instanceColor, or null for white
count int
how many copies to draw

Returns

this model

getInstanceCount

public int getInstanceCount()
Returns how many copies setInstances asked for, 0 for a single model.