目录

SceneObject

Class Info

class SceneObject

场景对象类,主要提供当前场景中组件管理,模型旋转、缩放,场景可见性配置,父场景配置,子场景配置等功能。

Public Constructor Summary

Constructor Name

SceneObject(const SceneManager* sceneManager,SceneObject* parent)

构造函数,若父类场景为空,则调用AddSceneObject函数添加自身作为场景对象,并作为父场景;否则调用SetParent设置父场景,参数为父场景对象指针。

Public Destructor Summary

Destructor Name

virtual ~SceneObject()

析构函数。

Public Method Summary

Qualifier and Type

Method Name and Description

void

SetName(const String& name)

设置当前场景对象的名称。

const String&

GetName() const

获取当前场景对象的名称。

void

SetSortId(u32 id)

设置当前场景对象的排序ID。

u32

GetSortId() const

获取当前场景对象的排序ID。

virtual void

PreUpdate(f32 deltaTime)

每帧预更新逻辑,可用于有物理更新逻辑的场景。

virtual void

Update(f32 deltaTime)

每帧更新逻辑,主要更新世界矩阵。

virtual void

PostUpdate(f32 deltaTime)

每帧后更新逻辑,可用于具有追随更新逻辑的场景,如相机追随某个对象,要滞后于对象的更新。

bool

RemoveComponent(IComponent* component)

删除指定组件。

template <typename T> T*

AddComponent()

模板,向组件列表中添加T类型组件并完成组件的启动。

template <typename T> T*

GetComponent() const

模板,获取组件列表中找到的第一个T类型组件。

template <typename T> vector<T*>

GetComponents()

模板,获取所有T类型组件。

const SceneObject*

GetParent() const

获取当前场景的父场景对象常量指针。

void

SetParent(SceneObject* newParent)

移除原有父场景对象,并设置新的父场景对象。

bool

HasParent() const

判断是否存在父场景。

bool

IsParentOf(const SceneObject* object) const

判断当前场景是否为指定场景的父场景。

const list<SceneObject*>&

GetChildren() const

获取子场景对象列表。

u32

GetChildrenCount() const

获取子场景对象总数。

void

AddChild(SceneObject* child)

添加子场景对象。

bool

RemoveChild(SceneObject* child)

删除指定子场景对象。

bool

IsChildOf(const SceneObject* object) const

判断当前场景对象是否为指定场景对象的子场景。

u32

GetID() const

获取当前场景对象ID。

void

SetNodeIndex(u32 nodeIndex)

设置当前场景对象的节点索引。

u32

GetNodeIndex() const

获取当前场景对象的节点索引。

void

SetVisible(bool visible)

设置当前场景对象是否可见。

bool

IsVisible() const

判断当前场景对象是否可见。

void

SetPosition(const Vector3& position)

设置当前场景对象在世界坐标系下的位置。

const Vector3&

GetPosition() const

获取当前场景对象在世界坐标系下的位置。

void

SetScale(const Vector3& scale)

设置当前场景对象在局部坐标系下的缩放向量(相对于父场景对象)。

const Vector3&

GetScale() const

获取当前场景对象在局部坐标系下的缩放向量(相对于父场景对象)。

void

SetRotation(const Vector3& rotation)

设置当前场景对象在局部坐标系下的旋转向量(相对于父场景对象)。

const Vector3&

GetRotation() const

获取当前场景对象在局部坐标系下的旋转向量(相对于父场景对象)。

const Transform*

GetTransform() const

获取当前场景对象绑定的坐标转换类接口。

const Transform*

GetParentTransform() const

获取父场景对象绑定的坐标转换类接口。

void

SetLocalPosition(const Vector3& position)

设置局部坐标系下,当前场景对象相对于父场景对象的位置。

MeshRenderer*

GetMeshRenderer()

获取网格渲染对象。

u32

GetLayerType() const

获取场景对象的类型。

void

SetLayerType(LayerType layerType)

设置场景对象的类型。

const SceneManager*

GetSceneManager() const

获取SceneManager指针。

template <typename T> std::vector<T*>

GetComponentsInChildren()

递归获取已包含的所有类型T的组件变量。

Public Constructors

[h2]SceneObject

Constructor

SceneObject(const SceneManager* sceneManager,SceneObject* parent)

构造函数,若父类场景为空,则调用AddSceneObject函数添加自身作为场景对象,并作为父场景;否则调用SetParent设置父场景。

Parameters

Name

Description

sceneManager

SceneManager指针。

parent

父场景对象指针。

Public Destructors

[h2]~SceneObject

Destructor

virtual ~SceneObject()

析构函数。

Public Methods

[h2]SetName

Method

void SetName(const String& name)

设置当前场景对象的名称。

Parameters

Name

Description

name

所需设置场景对象的名称。

[h2]GetName

Method

const String& GetName() const

获取当前场景对象的名称。

Returns

Type

Description

const String&

当前场景对象的名称。

[h2]SetSortId

Method

void SetSortId(u32 id)

设置当前场景对象的排序ID。

Parameters

Name

Description

id

所需设置场景对象的排序ID。

[h2]GetSortId

Method

u32 GetSortId() const

获取当前场景对象的排序ID。

Returns

Type

Description

u32

当前场景对象的排序ID。

[h2]PreUpdate

Method

virtual void PreUpdate(f32 deltaTime)

每帧预更新逻辑,可用于有物理更新逻辑的场景。

Parameters

Name

Description

deltaTime

帧间隔时间,单位为秒。

[h2]Update

Method

virtual void Update(f32 deltaTime)

每帧更新逻辑,主要更新世界矩阵。

Parameters

Name

Description

deltaTime

帧间隔时间,单位为秒。

[h2]PostUpdate

Method

virtual void PostUpdate(f32 deltaTime)

每帧后更新逻辑,可用于具有追随更新逻辑的场景,如相机追随某个对象,要滞后于对象的更新。

Parameters

Name

Description

deltaTime

帧间隔时间,单位为秒。

[h2]RemoveComponent

Method

bool RemoveComponent(IComponent* component)

删除指定组件。

Parameters

Name

Description

component

IComponent类型待删除的组件指针。

Returns

Type

Description

bool

  • true:删除成功。
  • false:删除失败。

[h2]AddComponent

Method

template <typename T> T* AddComponent()

模板,向组件列表中添加T类型组件并完成组件的启动。

Returns

Type

Description

template <typename T> T*

指向T类型组件的指针。

[h2]GetComponent

Method

template <typename T> T* GetComponent() const

模板,获取组件列表中找到的第一个T类型组件。

Returns

Type

Description

template <typename T> T*

指向组件列表中第一个T类型组件的指针。

[h2]GetComponents

Method

template <typename T> vector<T*> GetComponents()

模板,获取所有T类型组件。

Returns

Type

Description

template <typename T> vector<T*>

T类型组件列表。

[h2]GetParent

Method

const SceneObject* GetParent() const

获取当前场景的父场景对象常量指针。

Returns

Type

Description

const SceneObject*

当前场景的父场景对象常量指针。

[h2]SetParent

Method

void SetParent(SceneObject* newParent)

移除原有父场景对象,并设置新的父场景对象。

Parameters

Name

Description

newParent

SceneObject类型父场景指针。

[h2]HasParent

Method

bool HasParent() const

判断是否存在父场景。

Returns

Type

Description

bool

  • true:存在。
  • false:不存在。

[h2]IsParentOf

Method

bool IsParentOf(const SceneObject* object) const

判断当前场景是否为指定场景的父场景。

Parameters

Name

Description

object

SceneObject类型指向指定场景对象的指针。

Returns

Type

Description

bool

  • true:是。
  • false:不是。

[h2]GetChildren

Method

const list<SceneObject*>& GetChildren() const

获取子场景对象列表。

Returns

Type

Description

const list<SceneObject*>&

返回子场景对象列表。

[h2]GetChildrenCount

Method

u32 GetChildrenCount() const

获取子场景对象总数。

Returns

Type

Description

u32

返回子场景对象总数。

[h2]AddChild

Method

void AddChild(SceneObject* child)

添加子场景对象。

Parameters

Name

Description

child

SceneObject类型指向待添加子场景对象的指针。

[h2]RemoveChild

Method

bool RemoveChild(SceneObject* child)

删除指定子场景对象。

Parameters

Name

Description

child

SceneObject类型待删除的子场景对象指针。

Returns

Type

Description

bool

  • true:删除成功。
  • false:删除失败。

[h2]IsChildOf

Method

bool IsChildOf(const SceneObject* object) const

判断当前场景对象是否为指定场景对象的子场景。

Parameters

Name

Description

object

指向指定场景对象的指针。

Returns

Type

Description

bool

  • true:是。
  • false:不是。

[h2]GetID

Method

u32 GetID() const

获取当前场景对象ID。

Returns

Type

Description

u32

返回当前场景对象ID。

[h2]SetNodeIndex

Method

void SetNodeIndex(u32 nodeIndex)

设置当前场景对象的节点索引。

Parameters

Name

Description

nodeIndex

所需设置场景对象的节点索引。

[h2]GetNodeIndex

Method

u32 GetNodeIndex() const

获取当前场景对象的节点索引。

Returns

Type

Description

u32

当前场景对象的节点索引。

[h2]SetVisible

Method

void SetVisible(bool visible)

设置当前场景对象是否可见。

Parameters

Name

Description

visible

表示是否可见的布尔类型标志变量。

  • true:可见。
  • false:不可见。

[h2]IsVisible

Method

bool IsVisible() const

判断当前场景对象是否可见。

Returns

Type

Description

bool

  • true:可见。
  • false:不可见。

[h2]SetPosition

Method

void SetPosition(const Vector3& position)

设置当前场景对象在世界坐标系下的位置。

Parameters

Name

Description

position

Vector3类型位置的引用。

[h2]GetPosition

Method

const Vector3& GetPosition() const

获取当前场景对象在世界坐标系下的位置。

Returns

Type

Description

const Vector3&

Vector3类型的引用。

[h2]SetScale

Method

void SetScale(const Vector3& scale)

设置当前场景对象在局部坐标系下的缩放向量(相对于父场景对象)。

Parameters

Name

Description

scale

Vector3类型缩放向量。

[h2]GetScale

Method

const Vector3& GetScale() const

获取当前场景对象在局部坐标系下的缩放向量(相对于父场景对象)。

Returns

Type

Description

const Vector3&

场景对象在局部坐标下的缩放向量。

[h2]SetRotation

Method

void SetRotation(const Vector3& rotation)

设置当前场景对象在局部坐标系下的旋转向量(相对于父场景对象)。

Parameters

Name

Description

rotation

Vector3类型旋转向量,各个分量为弧度。

[h2]GetRotation

Method

const Vector3& GetRotation() const

获取当前场景对象在局部坐标系下的旋转向量(相对于父场景对象)。

Returns

Type

Description

const Vector3&

场景对象在局部坐标下的旋转向量,各分量的值为弧度。

[h2]GetTransform

Method

const Transform* GetTransform() const

获取当前场景对象绑定的坐标转换类接口。

Returns

Type

Description

const Transform*

指向当前场景对象绑定的坐标转换类接口的指针。

[h2]GetParentTransform

Method

const Transform* GetParentTransform() const

获取父场景对象绑定的坐标转换类接口。

Returns

Type

Description

const Transform*

  • 存在父场景对象,指向父场景对象绑定的坐标转换类接口的指针。
  • 不存在父场景对象,则返回空指针。

[h2]Scale

Method

void Scale(const Vector3& scale)

局部坐标系下的缩放变换。

Parameters

Name

Description

scale

缩放系数。

[h2]SetLocalPosition

Method

void SetLocalPosition(const Vector3& position)

设置局部坐标系下,当前场景对象相对于父场景对象的位置。

Parameters

Name

Description

position

Vector3类型局部坐标系下待设置的位置。

[h2]GetMeshRenderer

Method

MeshRenderer* GetMeshRenderer()

获取网格渲染对象。

Returns

Type

Description

MeshRenderer*

网格渲染对象。

[h2]GetLayerType

Method

u32 GetLayerType()

获取场景对象的类型。

Returns

Name

Description

u32

场景对象的类型。

[h2]SetLayerType

Method

void SetLayerType(LayerType layerType)

设置场景对象的类型。

Parameters

Name

Description

layerType

场景对象类型,具体请参见LayerType。

说明:
  • 若不设置,默认为LayerType::LAYER_TYPE_DEFAULT类型。
  • 相机和光源场景对象需要设置为LayerType::LAYER_TYPE_DEFAULT类型。

[h2]GetSceneManager

Method

const SceneManager* GetSceneManager() const

获取SceneManager指针。

Returns

Type

Description

SceneManager*

返回SceneManager指针。

[h2]GetComponentsInChildren

Method

template <typename T> std::vector<T*> GetComponentsInChildren()

递归获取已包含的所有类型T的组件变量。

Returns

Type

Description

template <typename T> std::vector<T*>

返回包含所有T类型组件的容器。