|
@@ -9,7 +9,7 @@ Defold is at its core a 3D engine. Even when you work with 2D material only all
|
|
|
|
|
|
## Creating a model
|
|
|
|
|
|
-Let's look at an example. We have created a simple model with an armature (skeleton) and a simple animation in _Blender_.
|
|
|
+Let's look at an example. We have created a simple model with an armature (skeleton) and a simple animation in _Blender_.
|
|
|
|
|
|
Blender is a powerful and popular 3D modeling, animation and rendering program. It runs on Windows, Mac OS X and Linux and is freely available for download at http://www.blender.org
|
|
|
|
|
@@ -36,6 +36,10 @@ Model components are created just like any other game object component. You can
|
|
|
|
|
|
With the model created you need to specify a number of properties:
|
|
|
|
|
|
+### Model properties
|
|
|
+
|
|
|
+Apart from the properties *Id*, *Position* and *Rotation* the following component specific properties exist:
|
|
|
+
|
|
|
*Mesh*
|
|
|
: This property should refer to the Collada *.dae* file that contains the mesh to use. If the file contains multiple meshes, only the first one is read.
|
|
|
|
|
@@ -54,9 +58,56 @@ With the model created you need to specify a number of properties:
|
|
|
*Default Animation*
|
|
|
: This is the animation (from the animation set) that will be automatically played on the model.
|
|
|
|
|
|
+## Editor manipulation
|
|
|
|
|
|
With the model component in place you are free to edit and manipulate the component and/or the encapsulating game object with the regular *Scene Editor* tools to move, rotate and scale the model to your liking.
|
|
|
|
|
|
{srcset="images/model/[email protected] 2x"}
|
|
|
|
|
|
+## Runtime manipulation
|
|
|
+
|
|
|
+You can manipulate models in runtime through a number of different functions and properties (refer to the [API docs for usage](/ref/model/)).
|
|
|
+
|
|
|
+### Runtime animation
|
|
|
+
|
|
|
+Defold provides powerful support for controlling animation in runtime:
|
|
|
+
|
|
|
+```lua
|
|
|
+local play_properties = { blend_duration = 0.1 }
|
|
|
+spine.play_anim("#model", "jump", go.PLAYBACK_ONCE_FORWARD, play_properties)
|
|
|
+```
|
|
|
+
|
|
|
+The animation playback cursor can be animated either by hand or through the property animation system:
|
|
|
+
|
|
|
+```lua
|
|
|
+-- set the run animation
|
|
|
+model.play_anim("#model", "run", go.PLAYBACK_NONE)
|
|
|
+-- animate the cursor
|
|
|
+go.animate("#model", "cursor", go.PLAYBACK_LOOP_PINGPONG, 1, go.EASING_LINEAR, 10)
|
|
|
+```
|
|
|
+
|
|
|
+### Changing properties
|
|
|
+
|
|
|
+A model also has a number of different properties that can be manipulated using `go.get()` and `go.set()`:
|
|
|
+
|
|
|
+`animation`
|
|
|
+: The current model animation (`hash`) (READ ONLY). You change animation using `model.play_anim()` (see above).
|
|
|
+
|
|
|
+`cursor`
|
|
|
+: The normalized animation cursor (`number`).
|
|
|
+
|
|
|
+`material`
|
|
|
+: The model material (`hash`). You can change this using a material resource property and `go.set()`. Refer to the [API reference for an example](/ref/model/#material).
|
|
|
+
|
|
|
+`playback_rate`
|
|
|
+: The animation playback rate (`number`).
|
|
|
+
|
|
|
+`textureN`
|
|
|
+: The model textures where N is 0-7 (`hash`). You can change this using a texture resource property and `go.set()`. Refer to the [API reference for an example](/ref/model/#textureN).
|
|
|
+
|
|
|
+## Material constants
|
|
|
+
|
|
|
+The default model material has the following constants that can be changed using `model.set_constant()` and reset using `model.reset_constant()` (refer to the [Material manual for more details](/manuals/material/#vertex-and-fragment-constants)):
|
|
|
|
|
|
+`tint`
|
|
|
+: The color tint of the model (`vector4`). The vector4 is used to represent the tint with x, y, z, and w corresponding to the red, green, blue and alpha tint. Refer to the [API reference for an example](/ref/model/#model.set_constant:url-constant-value).
|