init commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_component.h"
|
||||
#include "math/dvc_vector3.h"
|
||||
#include "math/dvc_matrix4.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API CameraComponent : public SceneComponent
|
||||
{
|
||||
public:
|
||||
struct CameraDefine
|
||||
{
|
||||
float32_t fov;
|
||||
float32_t aspect;
|
||||
float32_t nearClip;
|
||||
float32_t farClip;
|
||||
};
|
||||
public:
|
||||
virtual const std::string& getTypeName() const { return typeName(); }
|
||||
virtual void render(const fMatrix4& transParent, RenderQueue& queue) const;
|
||||
|
||||
fVector3 getEye(void) const;
|
||||
fVector3 getLookat(void) const;
|
||||
fVector3 getUp(void) const;
|
||||
|
||||
void setCameraDefine(const CameraDefine& cameraDefine);
|
||||
CameraDefine getCameraDefine() const {
|
||||
return m_cameraDefine;
|
||||
}
|
||||
|
||||
const fMatrix4& getViewMatrix(void) const {
|
||||
return m_viewMatrix;
|
||||
}
|
||||
|
||||
const fMatrix4& getViewProjMatrix(void) const {
|
||||
return m_viewProjMatrix;
|
||||
}
|
||||
|
||||
protected:
|
||||
CameraDefine m_cameraDefine;
|
||||
fMatrix4 m_viewMatrix;
|
||||
fMatrix4 m_viewProjMatrix;
|
||||
|
||||
public:
|
||||
CameraComponent(SceneNodePtr owner);
|
||||
virtual ~CameraComponent();
|
||||
|
||||
static const std::string& typeName();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "math/dvc_matrix4.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API SceneComponent
|
||||
{
|
||||
public:
|
||||
virtual const std::string& getTypeName() const = 0;
|
||||
virtual void render(const fMatrix4& transParent, RenderQueue& queue) const;
|
||||
|
||||
protected:
|
||||
SceneNodePtr m_owner;
|
||||
|
||||
public:
|
||||
SceneComponent(SceneNodePtr owner);
|
||||
virtual ~SceneComponent();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_component.h"
|
||||
#include "math/dvc_vector3.h"
|
||||
//#include
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API LightComponent : public SceneComponent
|
||||
{
|
||||
public:
|
||||
enum LightType
|
||||
{
|
||||
LT_Point,
|
||||
LT_Directional,
|
||||
LT_Spot,
|
||||
};
|
||||
struct LightDefine
|
||||
{
|
||||
LightType type;
|
||||
fVector3 color; //default is "1.0, 1.0, 1.0"
|
||||
float32_t intensity; //default is "1.0"
|
||||
float32_t range; //default is "-1", means infinite
|
||||
|
||||
float32_t innerConeAngle; //only for spot light, default is 0
|
||||
float32_t outerConeAngle; //only for spot light, default is PI/4.0
|
||||
};
|
||||
public:
|
||||
virtual const std::string& getTypeName() const { return typeName(); }
|
||||
virtual void render(const fMatrix4& transParent, RenderQueue& queue) const;
|
||||
|
||||
void setLightDefine(const LightDefine& lightDefine);
|
||||
protected:
|
||||
LightDefine m_define;
|
||||
|
||||
public:
|
||||
LightComponent(SceneNodePtr owner);
|
||||
virtual ~LightComponent();
|
||||
|
||||
static const std::string& typeName();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_component.h"
|
||||
#include "dvc_pre_declare.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API MeshComponent : public SceneComponent
|
||||
{
|
||||
public:
|
||||
virtual const std::string& getTypeName() const { return typeName(); }
|
||||
virtual void render(const fMatrix4& transParent, RenderQueue& queue) const;
|
||||
|
||||
void setMesh(MeshConstPtr mesh);
|
||||
|
||||
protected:
|
||||
MeshConstPtr m_mesh;
|
||||
|
||||
public:
|
||||
MeshComponent(SceneNodePtr owner);
|
||||
virtual ~MeshComponent();
|
||||
|
||||
static const std::string& typeName();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "dvc_pre_declare.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API Scene
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
void clear(void);
|
||||
|
||||
public:
|
||||
DeviceBufferPtr newDeviceBuffer(void);
|
||||
int32_t getDeviceBufferCounts(void) const {
|
||||
return (int32_t)m_deviceBufferArray.size();
|
||||
}
|
||||
DeviceBufferConstPtr getDeviceBuffer(int32_t index) const;
|
||||
|
||||
DeviceBufferViewPtr newDeviceBufferView(DeviceBufferConstPtr buffer, size_t offset, size_t length, size_t stride);
|
||||
int32_t getDeviceBufferViewCounts(void) const {
|
||||
return (int32_t)m_bufferViewArray.size();
|
||||
}
|
||||
DeviceBufferViewPtr getDeviceBufferView(int32_t index) const;
|
||||
|
||||
DeviceBufferAccessorPtr newDeviceBufferAccessor(DeviceBufferViewConstPtr bufferView, size_t offset,
|
||||
size_t count, ComponentType componentType, DataType dataType);
|
||||
int32_t getDeviceBufferAccessorCounts(void) const {
|
||||
return (int32_t)m_bufferAccessorArray.size();
|
||||
}
|
||||
DeviceBufferAccessorPtr getDeviceBufferAccessor(int32_t index) const;
|
||||
|
||||
int32_t pushNewMeshAsset(MeshPtr mesh);
|
||||
int32_t getMeshCounts(void) const {
|
||||
return (int32_t)m_meshArray.size();
|
||||
}
|
||||
MeshConstPtr getMesh(int32_t index) const;
|
||||
|
||||
public:
|
||||
SceneNodePtr newSceneNode(const std::string& name);
|
||||
SceneNodePtr getRootSceneNode() const;
|
||||
|
||||
public:
|
||||
template<typename ComponentType>
|
||||
SceneNodeConstPtr getNodeWithComponent(const char* name = nullptr) const
|
||||
{
|
||||
return getNodeWithComponent<ComponentType>(name, getRootSceneNode());
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
SceneNodeConstPtr getNodeWithComponent(const char* name, SceneNodeConstPtr node) const
|
||||
{
|
||||
size_t counts = node->getChildCounts();
|
||||
for (size_t i = 0; i < counts; i++)
|
||||
{
|
||||
SceneNodeConstPtr childNodePtr = node->getChild(i);
|
||||
if (name != nullptr && childNodePtr->getName() != name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::shared_ptr<const ComponentType> component = childNodePtr->getComponent<ComponentType>();
|
||||
if (component)
|
||||
{
|
||||
return childNodePtr;
|
||||
}
|
||||
|
||||
//get from child
|
||||
SceneNodeConstPtr cameraNode = getNodeWithComponent<ComponentType>(name, childNodePtr);
|
||||
if (cameraNode != nullptr)
|
||||
{
|
||||
return cameraNode;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
SceneNodePtr m_rootSceneNode;
|
||||
|
||||
//device resources
|
||||
std::vector<DeviceBufferPtr> m_deviceBufferArray;
|
||||
std::vector<DeviceBufferViewPtr> m_bufferViewArray;
|
||||
std::vector<DeviceBufferAccessorPtr> m_bufferAccessorArray;
|
||||
|
||||
//asset resources
|
||||
std::vector<MeshPtr> m_meshArray;
|
||||
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "math/dvc_matrix4.h"
|
||||
#include "math/dvc_vector3.h"
|
||||
#include "dvc_pre_declare.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API SceneNode : public std::enable_shared_from_this<SceneNode>
|
||||
{
|
||||
public:
|
||||
void clear(void);
|
||||
void addChild(SceneNodePtr child);
|
||||
void addComponent(SceneComponentPtr component);
|
||||
|
||||
void setName(const std::string& name);
|
||||
const std::string& getName() const;
|
||||
|
||||
void setParent(SceneNodePtr parent);
|
||||
|
||||
void setTransform(const fMatrix4& transform);
|
||||
const fMatrix4& getTransform() const {
|
||||
return m_transform;
|
||||
}
|
||||
fMatrix4 getWorldTransform() const;
|
||||
|
||||
fVector3 getPosition() const;
|
||||
fVector3 getWorldPosition() const;
|
||||
|
||||
size_t getChildCounts() const {
|
||||
return m_childen.size();
|
||||
}
|
||||
|
||||
SceneNodeConstPtr getChild(size_t index) const;
|
||||
|
||||
size_t getComponentCounts() const {
|
||||
return m_componentArray.size();
|
||||
}
|
||||
|
||||
SceneComponentConstPtr getComponent(size_t index) const;
|
||||
|
||||
template<typename T>
|
||||
const std::shared_ptr<const T> getComponent() const
|
||||
{
|
||||
for (size_t i = 0; i < getComponentCounts(); i++)
|
||||
{
|
||||
auto component = getComponent(i);
|
||||
if (component->getTypeName() == T::typeName())
|
||||
{
|
||||
return std::dynamic_pointer_cast<const T>(component);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
void buildRenderQueue(const fMatrix4& transParent, RenderQueue& queue);
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
fMatrix4 m_transform;
|
||||
SceneNodePtr m_parent;
|
||||
SceneNodeArray m_childen;
|
||||
SceneComponentArray m_componentArray;
|
||||
|
||||
public:
|
||||
SceneNode();
|
||||
virtual ~SceneNode();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user