-
Notifications
You must be signed in to change notification settings - Fork 21
Differences between 2D and 3D Scenes
If you look at how the RectangleEntity
is created in the 2D version of 03 Your first Component, there are a few subtle but important differences from the 3D version of the same tutorial. This is how the 2D components map to their 3D equivalents:
-
Entity
->MeshComponent
-
RectangleGeometryComponent
->CubeGeometryComponent
-
GeometrySkin
->ColorMaterialComponent
-
Transform2D
->MeshComponent
In the 2D example, the Entity
class doesn't actually do anything, it's simply a dressed up ComponentContainer
which provides a platform for future extension (should extension be required). The MeshComponent
is more specific than that, it's a wrapper for a away3d.entities.Mesh
.
The geometry components are very similar in both cases, they simply define a geometry which can be associated with a visual component and rendered.
GeometrySkin
and ColorMaterialComponent
both provide instructions for how the scene should render the geometry, but a Skin in the 2D system does more than a Material does in the 3D system.
In the 3D scene:
-
MeshComponent
wraps up aaway3d.entities.Mesh
-
ColorMaterialComponent
wraps up aaway3d.materials.ColorMaterial
-
CubeGeometryComponent
wraps up aaway3d.primitives.CubeGeometry
-
Renderer3D
wraps up an instance ofaway3d.containers.View3D
.
When renderer3D.validateNow()
is called, this calls view3d.render()
. As all of the CadetEngine objects are simply wrappers for Away3D objects which exist natively within the Away3D scene, Away3D takes care of the rendering internally; the CadetEngine wrapper Components only exist to give the Away3D objects a presence in the CadetEngine scene graph, enabling them to be editable via the CadetEditor.
In the 2D scene:
-
GeometrySkin
wraps up astarling.display.Shape
(from the Starling Graphics Extension) -
RectangleGeometry
is a native CadetEngine class with no Starling equivalent. -
Renderer2D
wraps up an instance ofstarling.core.Starling
.
In the 3D scene, it's the concept of a Mesh
which formalises the relationship between a Geometry, a Transform and a Material into one object. In the 2D scene there's no such concept, so rather than having a hardcoded relationship as per the Mesh
, the relationships between these objects happens in a plug-and-play manner via Component.addSiblingReference()
.