Big 3D update (WIP)

Former-commit-id: 9f55dae0521bded91640a7ea2d223a49a378c97c
This commit is contained in:
Lynix
2013-03-02 01:29:44 +01:00
parent a20818d66b
commit ab1fc99fcd
17 changed files with 1446 additions and 77 deletions

View File

@@ -1,4 +1,4 @@
// This file was automatically generated by Nazara
// This file was automatically generated on 20 Feb 2013 at 17:02:32
/*
Nazara Engine - 3D module
@@ -30,9 +30,13 @@
#define NAZARA_GLOBAL_3D_HPP
#include <Nazara/3D/3D.hpp>
#include <Nazara/3D/Camera.hpp>
#include <Nazara/3D/Config.hpp>
#include <Nazara/3D/Enums.hpp>
#include <Nazara/3D/Light.hpp>
#include <Nazara/3D/Model.hpp>
#include <Nazara/3D/Scene.hpp>
#include <Nazara/3D/SceneNode.hpp>
#include <Nazara/3D/SceneRoot.hpp>
#endif // NAZARA_GLOBAL_3D_HPP

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - 3D Module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CAMERA_HPP
#define NAZARA_CAMERA_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/3D/SceneNode.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
class NzRenderTarget;
class NAZARA_API NzCamera : public NzSceneNode
{
public:
NzCamera();
~NzCamera();
void Activate() const;
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;
float GetAspectRatio() const;
const NzBoundingBoxf& GetBoundingBox() const override;
float GetFOV() const;
const NzFrustumf& GetFrustum() const;
const NzMatrix4f& GetProjectionMatrix() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzVector3f& GetUpVector() const;
const NzMatrix4f& GetViewMatrix() const;
const NzRectf& GetViewport() const;
float GetZFar() const;
float GetZNear() const;
void SetFOV(float fov);
void SetUpVector(const NzVector3f& upVector);
void SetViewport(const NzRectf& viewport);
void SetZFar(float zFar);
void SetZNear(float zNear);
private:
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
void Invalidate();
bool IsVisible(const NzFrustumf& frustum) const override;
void Register();
void Unregister();
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
mutable NzFrustumf m_frustum;
mutable NzMatrix4f m_projectionMatrix;
mutable NzMatrix4f m_viewMatrix;
NzRectf m_viewport;
NzVector3f m_upVector;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable float m_aspectRatio;
float m_fov;
float m_zFar;
float m_zNear;
};
#endif // NAZARA_CAMERA_HPP

View File

@@ -18,10 +18,13 @@ enum nzLightType
enum nzSceneNodeType
{
nzSceneNodeType_Camera,
nzSceneNodeType_Light,
nzSceneNodeType_Model,
nzSceneNodeType_Root,
nzSceneNodeType_User,
nzSceneNodeType_Max = nzSceneNodeType_Model
nzSceneNodeType_Max = nzSceneNodeType_User
};
#endif // NAZARA_ENUMS_3D_HPP

View File

@@ -12,6 +12,8 @@
#include <Nazara/3D/SceneNode.hpp>
#include <Nazara/Core/Color.hpp>
class NzShader;
class NAZARA_API NzLight : public NzSceneNode
{
public:
@@ -19,9 +21,11 @@ class NAZARA_API NzLight : public NzSceneNode
NzLight(const NzLight& light);
~NzLight();
void Apply(unsigned int unit) const;
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
const NzAxisAlignedBox& GetAABB() const;
void Apply(const NzShader* shader, unsigned int lightUnit) const;
const NzBoundingBoxf& GetBoundingBox() const;
NzColor GetAmbientColor() const;
float GetAttenuation() const;
NzColor GetDiffuseColor() const;
@@ -32,6 +36,8 @@ class NAZARA_API NzLight : public NzSceneNode
nzSceneNodeType GetSceneNodeType() const;
NzColor GetSpecularColor() const;
bool IsVisible(const NzFrustumf& frustum) const;
void SetAmbientColor(const NzColor& ambient);
void SetAttenuation(float attenuation);
void SetDiffuseColor(const NzColor& diffuse);
@@ -43,10 +49,16 @@ class NAZARA_API NzLight : public NzSceneNode
NzLight& operator=(const NzLight& light);
private:
void Register();
void Unregister();
void UpdateFrustum();
nzLightType m_type;
NzBoundingBoxf m_boundingBox;
NzColor m_ambientColor;
NzColor m_diffuseColor;
NzColor m_specularColor;
bool m_boundingBoxUpdated;
float m_attenuation;
float m_innerAngle;
float m_outerAngle;

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/3D/SceneNode.hpp>
#include <Nazara/Core/Updatable.hpp>
#include <Nazara/Renderer/Material.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Mesh.hpp>
@@ -21,18 +22,27 @@ struct NzModelParameters
NzMaterialParams materialParams;
};
class NAZARA_API NzModel : public NzSceneNode
class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
{
friend class NzScene;
public:
NzModel();
NzModel(const NzModel& model);
~NzModel();
void AddToRenderQueue(NzRenderQueue& renderQueue) const;
void AdvanceAnimation(float elapsedTime);
void EnableAnimation(bool animation);
void EnableDraw(bool draw);
NzAnimation* GetAnimation() const;
const NzAxisAlignedBox& GetAABB() const;
const NzBoundingBoxf& GetBoundingBox() const;
NzMaterial* GetMaterial(unsigned int matIndex) const;
NzMaterial* GetMaterial(unsigned int skinIndex, unsigned int matIndex) const;
unsigned int GetMaterialCount() const;
unsigned int GetSkin() const;
unsigned int GetSkinCount() const;
NzMesh* GetMesh() const;
nzSceneNodeType GetSceneNodeType() const override;
@@ -41,6 +51,10 @@ class NAZARA_API NzModel : public NzSceneNode
bool HasAnimation() const;
bool IsAnimationEnabled() const;
bool IsDrawEnabled() const;
bool IsVisible(const NzFrustumf& frustum) const override;
bool LoadFromFile(const NzString& meshPath, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters());
bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters());
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters());
@@ -51,22 +65,32 @@ class NAZARA_API NzModel : public NzSceneNode
void SetMaterial(unsigned int matIndex, NzMaterial* material);
void SetMaterial(unsigned int skinIndex, unsigned int matIndex, NzMaterial* material);
void SetMesh(NzMesh* mesh, const NzModelParameters& parameters = NzModelParameters());
void SetSkin(unsigned int skin);
void SetSkinCount(unsigned int skinCount);
bool SetSequence(const NzString& sequenceName);
void SetSequence(unsigned int sequenceIndex);
void Update(float elapsedTime);
private:
void Invalidate() override;
void Register() override;
void Unregister() override;
void Update() override;
void UpdateBoundingBox() const;
std::vector<NzMaterial*> m_materials;
mutable NzBoundingBoxf m_boundingBox;
NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques
NzAnimation* m_animation;
NzMesh* m_mesh;
const NzSequence* m_currentSequence;
bool m_animationEnabled;
mutable bool m_boundingBoxUpdated;
bool m_drawEnabled;
float m_interpolation;
unsigned int m_currentFrame;
unsigned int m_matCount;
unsigned int m_nextFrame;
unsigned int m_skin;
unsigned int m_skinCount;
};

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - 3D Module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_RENDERQUEUE_HPP
#define NAZARA_RENDERQUEUE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <map>
#include <vector>
class NzDrawable;
class NzLight;
class NzMaterial;
class NzModel;
class NzSkeletalMesh;
class NzStaticMesh;
class NAZARA_API NzRenderQueue
{
public:
struct MaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
struct SkeletalMeshComparator
{
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
};
struct StaticMeshComparator
{
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
};
NzRenderQueue() = default;
~NzRenderQueue() = default;
void Clear();
struct SkeletalData
{
NzMatrix4f transformMatrix;
///TODO: Déplacer vers un container séparé qui ne serait pas sujer à Clear();
std::vector<NzMeshVertex> skinnedVertices;
};
typedef std::map<NzSkeletalMesh*, std::vector<SkeletalData>, SkeletalMeshComparator> SkeletalMeshContainer;
typedef std::map<NzStaticMesh*, std::vector<NzMatrix4f>, StaticMeshComparator> StaticMeshContainer;
std::map<NzMaterial*, SkeletalMeshContainer, MaterialComparator> visibleSkeletalModels;
std::map<NzMaterial*, StaticMeshContainer, MaterialComparator> visibleStaticModels;
std::vector<const NzDrawable*> otherDrawables;
std::vector<const NzLight*> directionnalLights;
std::vector<const NzLight*> visibleLights;
};
#endif // NAZARA_RENDERQUEUE_HPP

View File

@@ -0,0 +1,53 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - 3D Module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SCENE_HPP
#define NAZARA_SCENE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Updatable.hpp>
class NzCamera;
class NzLight;
class NzModel;
class NzSceneNode;
struct NzSceneImpl;
class NAZARA_API NzScene
{
friend NzCamera;
public:
NzScene();
~NzScene();
void Cull();
void Draw();
NzSceneNode& GetRoot() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;
void RegisterForUpdate(NzUpdatable* node);
void SetAmbientColor(const NzColor& color);
void SetUpdatePerSecond(unsigned int updatePerSecond);
void UnregisterForUpdate(NzUpdatable* node);
void Update();
void UpdateVisible();
operator const NzSceneNode&() const;
private:
void SetActiveCamera(const NzCamera* camera);
NzSceneImpl* m_impl;
};
#endif // NAZARA_SCENE_HPP

View File

@@ -9,16 +9,39 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/3D/Enums.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/3D/RenderQueue.hpp>
#include <Nazara/3D/Scene.hpp>
#include <Nazara/Math/BoundingBox.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Utility/Node.hpp>
class NzSceneNode : public NzNode
class NAZARA_API NzSceneNode : public NzNode
{
friend class NzScene;
public:
NzSceneNode();
NzSceneNode(const NzSceneNode& node);
virtual ~NzSceneNode();
virtual const NzAxisAlignedBox& GetAABB() const = 0;
virtual void AddToRenderQueue(NzRenderQueue& renderQueue) const = 0;
virtual const NzBoundingBoxf& GetBoundingBox() const = 0;
nzNodeType GetNodeType() const final;
NzScene* GetScene() const;
virtual nzSceneNodeType GetSceneNodeType() const = 0;
virtual bool IsVisible(const NzFrustumf& frustum) const = 0;
protected:
virtual void OnParenting(const NzNode* parent) override;
virtual void Register();
void SetScene(NzScene* scene);
virtual bool ShouldUpdateWhenVisible();
virtual void Unregister();
virtual void Update();
NzScene* m_scene;
};
#endif // NAZARA_SCENENODE_HPP

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - 3D Module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SCENEROOT_HPP
#define NAZARA_SCENEROOT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/3D/SceneNode.hpp>
struct NzSceneImpl;
class NAZARA_API NzSceneRoot : public NzSceneNode
{
friend struct NzSceneImpl;
public:
void AddToRenderQueue(NzRenderQueue& renderQueue) const override;
const NzBoundingBoxf& GetBoundingBox() const override;
nzSceneNodeType GetSceneNodeType() const override;
bool IsVisible(const NzFrustumf& frustum) const override;
private:
NzSceneRoot(NzScene* scene);
virtual ~NzSceneRoot();
void Register();
void Unregister();
};
#endif // NAZARA_SCENEROOT_HPP