-
Notifications
You must be signed in to change notification settings - Fork 8
Transform and SceneGraph
Rhodonite is a component-oriented library. Operations on Entity (an object in 3D space) are actually performed on the various components of Entity.
Therefore, we need to get the components from Entity first.
const cubeEntity = Rn.MeshHelper.createCube();
const cubeTransformComponent = cubeEntity.getTransform();The transform component allows you to manipulate translation, scale, and rotation in local coordinates for that Entity.
const cubeTransformComponent = cubeEntity.getTransform();
cubeTransformComponent.localPosition = Rn.Vector3.fromCopy3(0, 3, 0);
cubeTransformComponent.localEulerAngles = Rn.Vector3.fromCopy3(90, 0, 0);
cubeTransformComponent.localScale = Rn.Vector3.fromCopy3(2, 2, 2);The SceneGraph component allows you to build parent-child relationships between Entities.
const groupEntity = Rn.EntityHelper.createGroupEntity();
const cubeEntity = Rn.MeshHelper.createCube();
const groupSceneGraphComponent = groupEntity.getSceneGraph();
groupSceneGraphComponent.addChild(cubeEntity.getSceneGraph());It can also manipulate translations and rotations in world space.
const groupEntity = Rn.EntityHelper.createGroupEntity();
groupEntity.position = Rn.Vector3.fromCopy3(0, 3, 0);
groupEntity.eulerAngles = Rn.Vector3.fromCopy3(90, 0, 0);Thus, essentially, for any operation on Entity, you must first obtain the component of the corresponding function. However, for the Transform and SceneGraph components, there are also key methods in Entity itself as shortcuts, since they are often used.
const cubeEntity = Rn.MeshHelper.createCube();
cubeEntity.localPosition = Rn.Vector3.fromCopy3(0, 3, 0);
cubeEntity.localEulerAngles = Rn.Vector3.fromCopy3(90, 0, 0);
cubeEntity.localScale = Rn.Vector3.fromCopy3(2, 2, 2);
cubeEntity.position = Rn.Vector3.fromCopy3(0, 3, 0);
cubeEntity.eulerAngles = Rn.Vector3.fromCopy3(90, 0, 0);
const groupEntity = Rn.EntityHelper.createGroupEntity();
groupEntity.addChild(cubeEntity.getSceneGraph());You can learn about each of the shortcut methods provided in the following file
https://github.com/actnwit/RhodoniteTS/blob/master/src/foundation/components/Transform/ITransformEntity.ts https://github.com/actnwit/RhodoniteTS/blob/master/src/foundation/components/SceneGraph/ISceneGraphEntity.ts