-
-
Notifications
You must be signed in to change notification settings - Fork 36
Model
Last updated for g3d version 1.5.1
A g3d object that lets you draw 3D meshes with position, rotation, and scale.
A Model can be created using model = g3d.newModel(mesh, texture, translation, rotation, scale)
.
Use the function model:draw()
in love.draw
to draw a model to the screen.
Defaults to the built-in shader defined in shader.lua
.
You can modify this to have the Model render itself with your own custom shader.
Either computed from the obj given or set to the list of vertices given on creation of the Model.
Either loaded from the path or set to the image given on creation of the Model.
A Love mesh automatically computed from the given verts, texture, and vertexFormat.
love.graphics.newMesh(self.vertexFormat, self.verts, "triangles")
mesh:setTexture(self.texture)
The specified data that can be stored in each vertex, and in what datatype.
The default vertexFormat
should serve the vast majority of use cases, so you shouldn't have to worry about this unless you understand how it works and want to customize it.
The default vertexFormat
that comes preloaded in every g3d Model is listed below:
vertexFormat = {
{"VertexPosition", "float", 3},
{"VertexTexCoord", "float", 2},
{"VertexNormal", "float", 3},
{"VertexColor", "byte", 4},
}
Creates a new Model object.
Arguments:
-
mesh
- either a path to an obj file or a custom list of vectors.
-
texture
- either be a path to an image or a Love image object.
-
translation
optional, defaults to{0,0,0}
- a vector representing where the Model is in space.
-
rotation
optional, defaults to{0,0,0}
- a vector representing the rotation of the Model in space.
-
scale
optional, defaults to{1,1,1}
- a vector representing the scale of the Model in each axis.
Automatically adds normals to the Model's mesh.
The resulting normals are computed as face normals, instead of smoothed vertex normals.
Arguments:
-
isFlipped
optional, defaults tofalse
- a boolean that represents whether the normals should be flipped the opposite direction. Useful if your model has a different winding order from what g3d expects.
The arguments to this function are vectors in the form of {x,y,z}.
Sets the model's translation, rotation, and scale - collectively called the Model's transform.
Arguments:
-
translation
optional, defaults to{0,0,0}
- a vector representing where the Model is in space.
-
rotation
optional, defaults to{0,0,0}
- a vector representing the rotation of the Model in space.
-
scale
optional, defaults to{1,1,1}
- a vector representing the scale of the Model in each axis.
Set just the translation of this model.
Arguments:
-
tx
- a number representing the x coordinate
-
ty
- a number representing the y coordinate
-
tz
- a number representing the z coordinate
Set just the rotation of this model using Euler angles.
Arguments:
-
rx
- a number representing the x rotation
-
ry
- a number representing the y rotation
-
rz
- a number representing the z rotation
Set the model's rotation around the axis specified.
Arguments:
-
x
- a number representing the x axis of rotation
-
y
- a number representing the y axis of rotation
-
z
- a number representing the z axis of rotation
-
angle
- a number representing how much the model should rotate around the given axis, given in radians
Set just the rotation of this model using a quaternion.
Arguments:
-
x
- a number representing the first component of the quaternion
-
y
- a number representing the second component of the quaternion
-
z
- a number representing the third component of the quaternion
-
w
- a number representing the fourth component of the quaternion
Set just the scale of this model.
Arguments:
-
sx
- a number representing the scale in the x dimension
-
sy
- a number representing the scale in the y dimension
-
sz
- a number representing the scale in the z dimension
Draws the Model and updates all four uniform variables in g3d's vertex shader.
Arguments:
-
shader
optional, defaults to g3d's build in shader- a shader with which the model will be drawn
Compresses the model so that it takes less space in memory. This is mainly useful for models that have hundreds or thousands of triangles.
Note: This function requires FFI to be enabled. Also, models can no longer be used for collision detection after they have been compressed.