|
Aston2 engine can draw polygonal 3D objects.
To activate 3D mode use special attribute render="scene3d" in section paint:
...
<skin name="background">
<paint render="scene3d">
<obj3d model="teapot1.3ds"/>
<obj3d model="teapot2.3ds"/>
<obj3d model="teapot3.3ds"/>
</paint>
</skin>
...
|
As you see in this example, the section paint contains the sections obj3d in this case.
Let's consider typical obj3d in details:
...
<skin name="background">
<obj3d model="pot.3ds">
<material/>
<render_option/>
<camera/>
<transform/>
<light/>
</obj3d>
</skin>
...
|
The attribute model contains file name for object in standard 3DS format.
Also, Aston2 can support built-in object model="*QUAD*".
The section material contains description of object material:
...
<skin name="background">
<obj3d model="pot.3ds">
<material visible_face="cw"
light_mode="none"
diffuse_source="map"
diffuse_color="0xFF007700"
diffuse_image="flower.jpg"
diffuse_uv="vertex"
diffuse_op="replace"
reflection_source="map"
reflection_color="0"
reflection_image="reflection.jpg"
reflection_uv="chrome ball"
reflection_op="add"
/>
<render_option/>
<camera/>
<transform/>
<light/>
</obj3d>
</skin>
...
|
The attribute visible_face gives visibility of each side of polygon's face. Available values are:
- visible_face="cw" - clockwise sides only
- visible_face="ccw" - contra-clockwise sides only
- visible_face="both" - both of sides
The attribute light_mode used for dynamic lighting. Available values are:
- light_mode="none" - no dynamic lighting
- light_mode="flat" - calculate light for each face
- light_mode="gouround" - linear interpolation from each vertex (don't supported in current version of Aston2)
Now, let's consider the attribute group for first pass of material rendering.
The attribute diffuse_source gives color source for pixels in first pass of material rendering:
- diffuse_source="none" - skip this render pass
- diffuse_source="const" - fill all polygons by const color
- diffuse_source="face" - take from face color
- diffuse_source="vertex" - linear interpolation between vertex colors
- diffuse_source="map" - take from texture image (according texture coordinates)
The attribute diffuse_color defines color const in case when diffuse_source="const".
The attribute diffuse_image defines texture file name in case when diffuse_source="map".
The attribute diffuse_uv gives texture coordinates source:
- diffuse_uv="vertex" - from vertex info, usually it reads from 3DS file
- diffuse_uv="chrome ball" - calculates texture coordinates on the fly, for chrome reflection effect
The attribute diffuse_op means mathematical operation with object pixels (src) and previous screen pixels (dst):
diffuse_op="replace" | dst = src | writes new pixels over old pixels |
diffuse_op="blend" | dst = dst * (1 - alpha) + src * alpha | blend by alpha value |
diffuse_op="add" | dst = dst + src | addition |
diffuse_op="modulate" | dst = dst * src | multiplication |
Here are two attribute groups for first and second material rendering pass:
first pass | second pass |
diffuse_source | reflection_source |
diffuse_color | reflection_color |
diffuse_image | reflection_image |
diffuse_uv | reflection_uv |
diffuse_op | reflection_op |
Usually, second pass adds reflection effect.
That is why default values are (i.e. when it skipped in XML):
- diffuse_op="replace"
- diffuse_uv="vertex"
- reflection_op="add"
- reflection_uv="chrome ball"
Well, let's consider the section render_options. Section material in this example is reduced:
...
<skin name="background">
<obj3d model="pot.3ds">
<material/>
<render_option zsort="ranging"
rbuffer_size="20000"
flush_cache="0"
mag_filter="nearest"
z_adjust="best"
/>
<camera/>
<transform/>
<light/>
</obj3d>
</skin>
...
|
The attribute zsort gives method to sort polygons by deep distance (along Z-axis):
- zsort="none" - no sorting. It's fast, but can give incorrect looking (for example, if color operation is "replace" or "blend")
- zsort="ranging" - it's most fast solution, but it gives some restriction for 3d models
- zsort="z-buffer" - most accurate way, but slow with software rendering (not implement in current Ason2 version)
The attribute rbuffer_size gives size of ranging buffer (used when zsort="ranging").
The z-ranging sorting can work incorrect if this value less than total amount of polygons in scene.
The attribute flush_cache used to sort polygons of several 3d objects.
Set flush_cache="0" if obj3d is not last in scene.
The attribute mag_filter assigns texture magnifying filter.
- mag_filter="nearest" - 'nearest neighbour' - fast, but not accurate
- mag_filter="linear" - bi-linear filtering, finest, but slow
The attribute z_adjust gives perspective correction method:
- z_adjust="none" - fast, but rendering result can be distorted
- z_adjust="y_only" - corrects only along Y-axis, still fast
- z_adjust="full" - accurate, but slow
- z_adjust="fast" - most fastest method
- z_adjust="best" - most optimal method
- z_adjust="quality" - most accurate method
Next section is camera:
...
<skin name="background">
<obj3d model="pot.3ds">
<camera fov="1" aspect="1.25"/>
...
...
</obj3d>
</skin>
...
|
The attribute fov gives the field of view angle. Reasonable values belong to interval (0.5 - 2.0).
The attribute aspect gives width/height ratio for 3d-render view area.
For example, if a scene has being drawn on wallpaper with resolution 1024x768, than aspect ratio is 1024 / 768 = 1.25
Now, let's consider how to place 3d-object before virtual camera. To do this we need transform object coordinates.
Basic transformations are: move, scale and rotate. Typical transformation sequence looks like this:
...
<skin name="background">
<obj3d model="pot.3ds">
...
...
<transform op="scale" x="zoom" y="zoom" z="zoom"/>
<transform op="rotate" x="90"/>
<transform op="rotate" y="alpha"/>
<transform op="move" z="25"/>
</obj3d>
</skin>
...
|
In this example, following transformations are present:
- scaling by an animation variable "zoom"
- rotating on 90o along X-axis
- rotating by an animation variable "alpha" along Y-axis
- move along Z-axis on 25 units (place before virtual camera)
The animation variables are used for interactivity and animation effects.
For example, let's consider declaration of an variable "alpha":
...
<skin name="background">
<anim_vars name="a">
<frame alpha="0"/>
<frame alpha="360"/>
<sequence name="anim_Spawn">
<loop/>
<frame render="0" fps="0.1"/>
<frame render="1" fps="0"/>
</sequence>
</anim_vars>
</skin>
...
|
This looks like a declaration of animation for images.
The section anim_vars contains list of frames and list of sequences.
The attribute name="a" should give unique name for each anim_vars section
(it's name of animation context, rather than a variable!).
Each frame contains list of variable's names as attribute with its values.
Sequences declared same way as for image animation case.
Look at this indicator example, for clock widget:
...
<skin name="face">
<anim_vars name="1">
<frame a_hour="0"/>
<frame a_hour="720"/>
<indicator name="hour"/>
</anim_vars>
<anim_vars name="2">
<frame a_minute="0"/>
<frame a_minute="360"/>
<indicator name="minute"/>
</anim_vars>
</skin>
...
|
As you already guess, "a_hour" and "a_minute" can be used as animation variables for rotation angles of clock hands.
And finally, let's consider how define light for dynamic lighted objects (when light_mode="flat"):
...
<skin name="background">
<obj3d model="pot.3ds">
<material light_mode="flat" diffuse_source="none"/>
<light type="ambient" color="0xFF111111"/>
<light type="directional" dir_x="-1" dir_y="-3" dir_z="3" color="0xFF017eff"/>
<light type="directional" dir_x="1" dir_y="3" dir_z="3" color="0xFF002266"/>
...
...
...
</obj3d>
</skin>
...
|
Light sources list declared via sections light.
The attribute type gives light type:
- type="ambient" for ambient light part
- type="directional" for directional light source
Direction of light defined via dir_x, dir_y and dir_z (in case when type="directional").

| |