Merge remote-tracking branch 'origin/Importer' into Animations

# Conflicts:
#	src/Engine/Rendering/DrawFinalPass.cpp
This commit is contained in:
viktorljung
2016-02-02 15:01:34 +01:00
28 changed files with 883 additions and 375 deletions
+1 -1
Submodule assets updated: e4dc9529f2...9b2fa74a6d
+9
View File
@@ -30,9 +30,18 @@ public:
private: private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const; void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const; void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const;
void DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& job, RenderScene& scene);
void BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene);
void BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene);
void BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& job);
void BindModelTextures(std::shared_ptr<ModelJob>& job);
Texture* m_WhiteTexture; Texture* m_WhiteTexture;
Texture* m_BlackTexture; Texture* m_BlackTexture;
Texture* m_NeutralNormalTexture;
Texture* m_GreyTexture;
FrameBuffer m_FinalPassFrameBuffer; FrameBuffer m_FinalPassFrameBuffer;
GLuint m_BloomTexture; GLuint m_BloomTexture;
+20 -5
View File
@@ -22,10 +22,26 @@ struct ModelJob : RenderJob
{ {
Model = model; Model = model;
TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0; TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0;
DiffuseTexture = matGroup.Texture.get(); if (modelComponent["DiffuseTexture"]) {
NormalTexture = matGroup.NormalMap.get(); DiffuseTexture = matGroup.Texture.get();
SpecularTexture = matGroup.SpecularMap.get(); } else {
IncandescenceTexture = matGroup.IncandescenceMap.get(); DiffuseTexture = nullptr;
}
if (modelComponent["NormalMap"]) {
NormalTexture = matGroup.NormalMap.get();
} else {
NormalTexture = nullptr;
}
if (modelComponent["SpecularMap"]) {
SpecularTexture = matGroup.SpecularMap.get();
} else {
SpecularTexture = nullptr;
}
if (modelComponent["GlowMap"]) {
IncandescenceTexture = matGroup.IncandescenceMap.get();
} else {
IncandescenceTexture = nullptr;
}
DiffuseColor = matGroup.DiffuseColor; DiffuseColor = matGroup.DiffuseColor;
SpecularColor = matGroup.SpecularColor; SpecularColor = matGroup.SpecularColor;
IncandescenceColor = matGroup.IncandescenceColor; IncandescenceColor = matGroup.IncandescenceColor;
@@ -39,7 +55,6 @@ struct ModelJob : RenderJob
Depth = worldpos.z; Depth = worldpos.z;
World = world; World = world;
FillColor = fillColor; FillColor = fillColor;
FillPercentage = fillPercentage; FillPercentage = fillPercentage;
+1 -1
View File
@@ -89,7 +89,7 @@ private:
void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize);
void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips); void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips);
void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex); void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex);
void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfJoints, Skeleton::Animation& animation); void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, Skeleton::Animation& animation);
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID); //void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
}; };
+4 -2
View File
@@ -19,7 +19,8 @@
struct RenderScene struct RenderScene
{ {
::Camera* Camera = nullptr; ::Camera* Camera = nullptr;
std::list<std::shared_ptr<RenderJob>> ForwardJobs; std::list<std::shared_ptr<RenderJob>> OpaqueObjects;
std::list<std::shared_ptr<RenderJob>> TransparentObjects;
std::list<std::shared_ptr<RenderJob>> PointLightJobs; std::list<std::shared_ptr<RenderJob>> PointLightJobs;
std::list<std::shared_ptr<RenderJob>> TextJobs; std::list<std::shared_ptr<RenderJob>> TextJobs;
std::list<std::shared_ptr<RenderJob>> DirectionalLightJobs; std::list<std::shared_ptr<RenderJob>> DirectionalLightJobs;
@@ -28,7 +29,8 @@ struct RenderScene
void Clear() void Clear()
{ {
ForwardJobs.clear(); OpaqueObjects.clear();
TransparentObjects.clear();
PointLightJobs.clear(); PointLightJobs.clear();
TextJobs.clear(); TextJobs.clear();
DirectionalLightJobs.clear(); DirectionalLightJobs.clear();
+1 -1
View File
@@ -40,10 +40,10 @@ private:
EventRelay<RenderSystem, Events::PlayerSpawned> m_EPlayerSpawned; EventRelay<RenderSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(Events::PlayerSpawned& e); bool OnPlayerSpawned(Events::PlayerSpawned& e);
void fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs, std::list<std::shared_ptr<RenderJob>>& transparentJobs);
void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world); void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world); void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world); void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs);
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs); void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs);
bool isChildOfACamera(EntityWrapper entity); bool isChildOfACamera(EntityWrapper entity);
bool isChildOfCurrentCamera(EntityWrapper entity); bool isChildOfCurrentCamera(EntityWrapper entity);
+5
View File
@@ -2,5 +2,10 @@
<Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Model.xsd"> <Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Model.xsd">
<Resource></Resource> <Resource></Resource>
<Color R="1" G="1" B="1" A="1"/> <Color R="1" G="1" B="1" A="1"/>
<Transparent>false</Transparent>
<Visible>true</Visible> <Visible>true</Visible>
<DiffuseTexture>true</DiffuseTexture>
<NormalMap>true</NormalMap>
<SpecularMap>true</SpecularMap>
<GlowMap>true</GlowMap>
</Model> </Model>
+15
View File
@@ -15,9 +15,24 @@
<xs:element name="Color" type="t:Color" minOccurs="0"> <xs:element name="Color" type="t:Color" minOccurs="0">
<xs:annotation><xs:documentation>Color tint</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>Color tint</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="Transparent" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Wether the model is transparent or not</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Visible" type="t:bool" minOccurs="0"> <xs:element name="Visible" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model is visible or not</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>Whether the model is visible or not</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="DiffuseTexture" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model should use the Diffuse texture or not</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="NormalMap" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model should use the Normalmap or not</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="SpecularMap" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model should use the Specularmap or not</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="GlowMap" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model should use the Glowmap or not</xs:documentation></xs:annotation>
</xs:element>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
+221 -37
View File
@@ -6,7 +6,7 @@
</Components> </Components>
<Children> <Children>
<Entity> <Entity name="Ground">
<Components> <Components>
<c:Model> <c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource> <Resource>Models/Core/UnitCube.mesh</Resource>
@@ -18,69 +18,51 @@
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity>
<Components>
<c:Model>
<Resource>An error</Resource>
</c:Model>
<c:Transform>
<Position X="1" Y="1" Z="0"/>
<Orientation X="0" Y="0.785390019" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>An error</Resource>
</c:Model>
<c:Transform>
<Position X="2" Y="0" Z="0"/>
<Orientation X="0" Y="0.785390019" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity> <Entity>
<Components> <Components>
<c:Camera/> <c:Camera/>
<c:Listener/> <c:Listener/>
<c:Transform> <c:Transform>
<Position X="1.36896265" Y="4.4259491" Z="10.6640663"/> <Position X="1.36896265" Y="4.10503054" Z="10.6640663"/>
<Orientation X="-0.0349078141" Y="0.157154545" Z="-2.60252193e-07"/> <Orientation X="-0.0349078141" Y="0.157154545" Z="-2.60252193e-07"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity> <Entity name="DirectionalLight">
<Components> <Components>
<c:DirectionalLight/> <c:DirectionalLight>
<Intensity>0.80000001192092896</Intensity>
</c:DirectionalLight>
<c:Model> <c:Model>
<Resource>Models/DirectionalLightWidget.mesh</Resource> <Resource>Models/DirectionalLightWidget.mesh</Resource>
</c:Model> </c:Model>
<c:RaptorCopter>
<Speed>1.0499999523162842</Speed>
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform> <c:Transform>
<Position X="2.1529963" Y="6.59221172" Z="0.169116676"/> <Position X="2.1529963" Y="6.59221172" Z="0.169116676"/>
<Orientation X="4.32000017" Y="4.6340003" Z="0"/> <Orientation X="4.16300011" Y="1422.89319" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity> <Entity name="AssaultTPose">
<Components> <Components>
<c:Model> <c:Model>
<Resource>Models/Assault.mesh</Resource> <Resource>Models/Assault.mesh</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-2.00568962" Y="0.527161121" Z="0"/> <Position X="-1.68900967" Y="0.527161121" Z="-1.59648728"/>
<Orientation X="0" Y="1.64900005" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
<Entity> <Entity name="SecondaryWeapon">
<Components> <Components>
<c:Model> <c:Model>
<Resource>Models/SecondaryWeapon.fbx</Resource> <Resource>Models/SecondaryWeapon.mesh</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-0.546139359" Y="0.853016734" Z="0.177482292"/> <Position X="-0.546139359" Y="0.853016734" Z="0.177482292"/>
@@ -91,17 +73,219 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity> <Entity name="AnimationGroupOrigin">
<Components>
<c:Transform>
<Position X="1.11190474" Y="0.490183681" Z="0"/>
<Orientation X="0" Y="1.02100003" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="RunAnim">
<Components>
<c:Animation>
<Name>Run</Name>
<Time>0.62051775215976157</Time>
<Speed>1</Speed>
</c:Animation>
<c:Model>
<Resource>models/AssaultAnimated.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.786919653" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Walkanim">
<Components>
<c:Animation>
<Name>Walk</Name>
<Time>0.28779680073140668</Time>
<Speed>1</Speed>
</c:Animation>
<c:Model>
<Resource>models/AssaultAnimated.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity name="UnitSphere">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="0.294117659" B="19.6078434" G="1.17647064" R="0.0392156877"/>
<Transparent>true</Transparent>
</c:Model>
<c:Transform>
<Position X="0" Y="0.754540265" Z="0"/>
<Scale X="0.800000012" Y="1.9000001" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="Log">
<Components> <Components>
<c:Model> <c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource> <Resource>Models/Log.mesh</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0" Y="3.70000029" Z="0"/> <Position X="-4" Y="0.698000014" Z="-1"/>
<Orientation X="0" Y="2.74900007" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity name="SpheresOrigin">
<Components>
<c:Transform>
<Position X="6.80000019" Y="4.9000001" Z="-5.9000001"/>
</c:Transform>
</Components>
<Children>
<Entity name="NormalSphere">
<Components>
<c:Model>
<Resource>Models/NormalMapSphere.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="1.82700014" Y="0" Z="-0.166000009"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="SpecularSphere">
<Components>
<c:Model>
<Resource>Models/SpecularMapSphere.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-1.06487739" Y="0" Z="1.52336037"/>
</c:Transform>
</Components>
<Children>
<Entity name="Rotationpoint">
<Components>
<c:RaptorCopter>
<Speed>1</Speed>
<Axis X="0.699999988" Y="1" Z="0.300000012"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="404.200684" Y="577.428955" Z="173.228897"/>
</c:Transform>
</Components>
<Children>
<Entity name="PointLight">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="0" G="3.92156863" R="3.92156863"/>
</c:Model>
<c:PointLight>
<Radius>3</Radius>
<Intensity>1.1399998664855957</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0.600000024" Y="0.5" Z="0"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="GlowMap">
<Components>
<c:Model>
<Resource>Models/IncandescenceMapSphere.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-1.10000002" Y="0" Z="-1.80000007"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="CombinedSpheres">
<Components>
<c:Model>
<Resource>models/NormSpecIncdMapSphere.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="RotationPoint">
<Components>
<c:RaptorCopter>
<Speed>1</Speed>
<Axis X="1" Y="1" Z="1"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="53.9495354" Y="53.9495354" Z="53.9495354"/>
</c:Transform>
</Components>
<Children>
<Entity name="PointLight">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="0" G="3.92156863" R="3.92156863"/>
</c:Model>
<c:PointLight>
<Radius>3</Radius>
<Intensity>1.1399998664855957</Intensity>
</c:PointLight>
<c:Transform>
<Position X="-1.70000005" Y="0" Z="0"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="PointLight">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="0" G="3.92156863" R="3.92156863"/>
</c:Model>
<c:PointLight>
<Radius>5.0100002288818359</Radius>
<Intensity>0.69999998807907104</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0.900000036" Y="1.10000002" Z="0"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="PointLight">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="0" G="3.92156863" R="3.92156863"/>
</c:Model>
<c:PointLight>
<Radius>4</Radius>
<Intensity>0.80000001192092896</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0.400000006" Y="-1" Z="-1.50000012"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children> </Children>
</Entity> </Entity>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="PointLight" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="0" G="3.92156863" R="3.92156863"/>
</c:Model>
<c:PointLight>
<Radius>3</Radius>
<Intensity>1.1399998664855957</Intensity>
</c:PointLight>
<c:Transform>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+16 -19
View File
@@ -9,7 +9,9 @@ uniform vec2 ScreenDimensions;
uniform vec4 FillColor; uniform vec4 FillColor;
uniform float FillPercentage; uniform float FillPercentage;
layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 0) uniform sampler2D DiffuseTexture;
layout (binding = 1) uniform sampler2D GlowMap; layout (binding = 1) uniform sampler2D NormalMapTexture;
layout (binding = 2) uniform sampler2D SpecularMapTexture;
layout (binding = 3) uniform sampler2D GlowMapTexture;
#define TILE_SIZE 16 #define TILE_SIZE 16
@@ -49,6 +51,8 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{ in VertexData{
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate; vec2 TextureCoordinate;
vec4 ExplosionColor; vec4 ExplosionColor;
}Input; }Input;
@@ -102,13 +106,21 @@ LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensi
return result; return result;
} }
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}
void main() void main()
{ {
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate);
vec4 glowTexel = texture2D(GlowMap, Input.TextureCoordinate); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate);
vec4 position = V * M * vec4(Input.Position, 1.0); vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, NormalMapTexture);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-position); vec4 viewVec = normalize(-position);
vec2 tilePos; vec2 tilePos;
@@ -139,7 +151,7 @@ void main()
} }
vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color; vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
@@ -147,25 +159,10 @@ void main()
if(pos <= FillPercentage) { if(pos <= FillPercentage) {
color_result += FillColor; color_result += FillColor;
} }
//bloomColor = vec4(0.3, 0.8, 0.6, 1.0);
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//These if statements should be removed if they are slow.
color_result += glowTexel; color_result += glowTexel;
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0);
/*
if(color_result.x > 1 || color_result.y > 1 || color_result.z > 1) {
bloomColor = vec4(color_result.xyz, 1.0);
} else {
bloomColor = vec4(0.0, 0.0, 0.0, 1.0);
} */
//Tiled Debug Code //Tiled Debug Code
/* /*
+4
View File
@@ -16,6 +16,8 @@ layout(location = 6) in vec4 BoneWeights;
out VertexData{ out VertexData{
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate; vec2 TextureCoordinate;
vec4 ExplosionColor; vec4 ExplosionColor;
}Output; }Output;
@@ -37,5 +39,7 @@ void main()
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
Output.TextureCoordinate = TextureCoords; Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(M * vec4(Normal, 0.0)); Output.Normal = vec3(M * vec4(Normal, 0.0));
Output.Tangent = vec3(M * vec4(Tangent, 0.0));
Output.BiTangent = vec3(M * vec4(BiTangent, 0.0));
Output.ExplosionColor = vec4(0.0); Output.ExplosionColor = vec4(0.0);
} }
@@ -1,4 +1,5 @@
#version 430 #version 430
#extension GL_EXT_gpu_shader4 : enable
layout (binding = 0) uniform sampler2D Texture; layout (binding = 0) uniform sampler2D Texture;
@@ -1,4 +1,5 @@
#version 430 #version 430
#extension GL_EXT_gpu_shader4 : enable
layout (binding = 0) uniform sampler2D Texture; layout (binding = 0) uniform sampler2D Texture;
+5 -1
View File
@@ -49,7 +49,11 @@ void EditorRenderSystem::Update(double dt)
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World); glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
for (auto matGroup : model->MaterialGroups()) { for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f); std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f);
scene.ForwardJobs.push_back(modelJob); if(cModel["Transparent"]) {
scene.TransparentObjects.push_back(modelJob);
} else {
scene.OpaqueObjects.push_back(modelJob);
}
} }
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer)
void DrawBloomPass::InitializeTextures() void DrawBloomPass::InitializeTextures()
{ {
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
} }
void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeShaderPrograms()
+160 -112
View File
@@ -11,8 +11,10 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
void DrawFinalPass::InitializeTextures() void DrawFinalPass::InitializeTextures()
{ {
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png"); m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png");
m_NeutralNormalTexture = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
m_GreyTexture = ResourceManager::Load<Texture>("Textures/Core/Grey.png");
} }
void DrawFinalPass::InitializeFrameBuffers() void DrawFinalPass::InitializeFrameBuffers()
@@ -58,117 +60,15 @@ void DrawFinalPass::Draw(RenderScene& scene)
GLERROR("DrawFinalPass::Draw: Pre"); GLERROR("DrawFinalPass::Draw: Pre");
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle()); DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
GLuint shaderHandle; if (scene.ClearDepth) {
glClear(GL_DEPTH_BUFFER_BIT);
//TODO: Render: Add code for more jobs than modeljobs.
for (auto &job : scene.ForwardJobs) {
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
if (explosionEffectJob) {
m_ExplosionEffectProgram->Bind();
shaderHandle = m_ExplosionEffectProgram->GetHandle(); //---
GLERROR("DrawFinalPass::ExplosionEffect: 1");
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(explosionEffectJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(explosionEffectJob->Color));
glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(explosionEffectJob->ExplosionOrigin));
glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), explosionEffectJob->TimeSinceDeath);
glUniform1f(glGetUniformLocation(shaderHandle, "ExplosionDuration"), explosionEffectJob->ExplosionDuration);
glUniform4fv(glGetUniformLocation(shaderHandle, "EndColor"), 1, glm::value_ptr(explosionEffectJob->EndColor));
glUniform1i(glGetUniformLocation(shaderHandle, "Randomness"), explosionEffectJob->Randomness);
glUniform1fv(glGetUniformLocation(shaderHandle, "RandomNumbers"), 50, explosionEffectJob->RandomNumbers.data());
glUniform1f(glGetUniformLocation(shaderHandle, "RandomnessScalar"), explosionEffectJob->RandomnessScalar);
glUniform2fv(glGetUniformLocation(shaderHandle, "Velocity"), 1, glm::value_ptr(explosionEffectJob->Velocity));
glUniform1i(glGetUniformLocation(shaderHandle, "ColorByDistance"), explosionEffectJob->ColorByDistance);
glUniform1i(glGetUniformLocation(shaderHandle, "ExponentialAccelaration"), explosionEffectJob->ExponentialAccelaration);
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(explosionEffectJob->DiffuseColor));
GLERROR("DrawFinalPass::ExplosionEffect: 2");
if (explosionEffectJob->Model->m_RawModel->m_Skeleton != nullptr) {
std::vector<glm::mat4> frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animation, explosionEffectJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
if (explosionEffectJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, explosionEffectJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
GLERROR("DrawFinalPass::ExplosionEffect: END");
//m_ExplosionEffectProgram->Unbind();
} else {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
m_ForwardPlusProgram->Bind();
GLERROR("1.1");
shaderHandle = m_ForwardPlusProgram->GetHandle();
if (scene.ClearDepth) {
glClear(GL_DEPTH_BUFFER_BIT);
}
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height);
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(modelJob->DiffuseColor));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(modelJob->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), modelJob->FillPercentage);
if (modelJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (modelJob->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
/*if(modelJob->GlowMap != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}*/
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
GLERROR("DrawFinalPass::Model: END");
// m_ForwardPlusProgram->Unbind();
}
}
} }
DrawModelRenderQueues(scene.OpaqueObjects, scene);
GLERROR("DrawFinalPass::Draw: OpaqueObjects");
DrawModelRenderQueues(scene.TransparentObjects, scene);
GLERROR("DrawFinalPass::Draw: TransparentObjects");
GLERROR("DrawFinalPass::Draw: END"); GLERROR("DrawFinalPass::Draw: END");
delete state; delete state;
} }
@@ -206,4 +106,152 @@ void DrawFinalPass::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
GLERROR("MipMap Texture initialization failed"); GLERROR("MipMap Texture initialization failed");
} }
void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& job, RenderScene& scene)
{
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
for(auto &job : job)
{
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
if(explosionEffectJob) {
//Bind program
m_ExplosionEffectProgram->Bind();
//Bind uniforms
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
if (explosionEffectJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (explosionEffectJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = explosionEffectJob->Skeleton->GetFrameBones(*explosionEffectJob->Animation, explosionEffectJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
//bind textures
BindExplosionTextures(explosionEffectJob);
//draw
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
} else {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
//bind forward program
m_ForwardPlusProgram->Bind();
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
BindModelTextures(modelJob);
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones(*modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
//draw
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
GLERROR("DrawFinalPass::Model: END");
}
}
}
}
void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene)
{
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color));
glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(job->ExplosionOrigin));
glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), job->TimeSinceDeath);
glUniform1f(glGetUniformLocation(shaderHandle, "ExplosionDuration"), job->ExplosionDuration);
glUniform4fv(glGetUniformLocation(shaderHandle, "EndColor"), 1, glm::value_ptr(job->EndColor));
glUniform1i(glGetUniformLocation(shaderHandle, "Randomness"), job->Randomness);
glUniform1f(glGetUniformLocation(shaderHandle, "RandomnessScalar"), job->RandomnessScalar);
glUniform2fv(glGetUniformLocation(shaderHandle, "Velocity"), 1, glm::value_ptr(job->Velocity));
glUniform1i(glGetUniformLocation(shaderHandle, "ColorByDistance"), job->ColorByDistance);
glUniform1i(glGetUniformLocation(shaderHandle, "ExponentialAccelaration"), job->ExponentialAccelaration);
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(job->DiffuseColor));
glUniform1fv(glGetUniformLocation(shaderHandle, "RandomNumbers"), 50, job->RandomNumbers.data());
}
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
{
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(job->DiffuseColor));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(job->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage);
}
void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& job)
{
glActiveTexture(GL_TEXTURE0);
if (job->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (job->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
}
void DrawFinalPass::BindModelTextures(std::shared_ptr<ModelJob>& job)
{
glActiveTexture(GL_TEXTURE0);
if (job->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (job->NormalTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE2);
if (job->SpecularTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE3);
if (job->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
}
+47 -1
View File
@@ -56,7 +56,7 @@ void PickingPass::Draw(RenderScene& scene)
} }
m_Camera = scene.Camera; m_Camera = scene.Camera;
for (auto &job : scene.ForwardJobs) { for (auto &job : scene.OpaqueObjects) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job); auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) { if (modelJob) {
@@ -98,6 +98,52 @@ void PickingPass::Draw(RenderScene& scene)
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
} }
} }
for (auto &job : scene.TransparentObjects) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
int pickColor[2] = { m_ColorCounter[0], m_ColorCounter[1] };
PickingInfo pickInfo;
pickInfo.Entity = modelJob->Entity;
pickInfo.World = modelJob->World;
pickInfo.Camera = scene.Camera;
auto color = m_EntityColors.find(std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera));
if (color != m_EntityColors.end()) {
pickColor[0] = color->second[0];
pickColor[1] = color->second[1];
} else {
m_EntityColors[std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera)] = glm::ivec2(pickColor[0], pickColor[1]);
if (m_ColorCounter[0] > 255) {
m_ColorCounter[0] = 0;
m_ColorCounter[1] += 5;
} else {
m_ColorCounter[0] += 50;
}
}
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones(*modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
m_PickingBuffer.Unbind(); m_PickingBuffer.Unbind();
GLERROR("PickingPass Error"); GLERROR("PickingPass Error");
+8 -8
View File
@@ -327,22 +327,16 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
unsigned int nrOfKeyframes = *(unsigned int*)(fileData + offset); unsigned int nrOfKeyframes = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int); offset += sizeof(unsigned int);
if (offset + sizeof(unsigned int) > fileByteSize) {
throw Resource::FailedLoadingException("Reading AnimationClip NrOfJoints failed");
}
unsigned int nrOfJoints = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
newAnimation.Keyframes.reserve(nrOfKeyframes); newAnimation.Keyframes.reserve(nrOfKeyframes);
for (unsigned int i = 0; i < nrOfKeyframes; i++) { for (unsigned int i = 0; i < nrOfKeyframes; i++) {
ReadAnimationKeyFrame(offset, fileData, fileByteSize, nrOfJoints, newAnimation); ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation);
} }
m_Skeleton->Animations[newAnimation.Name] = newAnimation; m_Skeleton->Animations[newAnimation.Name] = newAnimation;
#else #else
#endif #endif
} }
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation) void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, Skeleton::Animation& animation)
{ {
Skeleton::Animation::Keyframe newKeyFrame; Skeleton::Animation::Keyframe newKeyFrame;
@@ -358,6 +352,12 @@ void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData,
newKeyFrame.Time = *(float*)(fileData + offset); newKeyFrame.Time = *(float*)(fileData + offset);
offset += sizeof(float); offset += sizeof(float);
if (offset + sizeof(unsigned int) > fileByteSize) {
throw Resource::FailedLoadingException("Reading AnimationKeyFrame NrOfJoints failed");
}
unsigned int nrOfJoints = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) { if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) {
throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed"); throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed");
} }
+19 -6
View File
@@ -35,13 +35,12 @@ bool RenderSystem::isChildOfACamera(EntityWrapper entity)
{ {
return entity.FirstParentWithComponent("Camera").Valid(); return entity.FirstParentWithComponent("Camera").Valid();
} }
bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity) bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity)
{ {
return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera); return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera);
} }
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs) void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs, std::list<std::shared_ptr<RenderJob>>& transparentJobs)
{ {
auto models = m_World->GetComponents("Model"); auto models = m_World->GetComponents("Model");
if (models == nullptr) { if (models == nullptr) {
@@ -84,7 +83,6 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
} }
} }
float fillPercentage = 0.f; float fillPercentage = 0.f;
glm::vec4 fillColor = glm::vec4(0); glm::vec4 fillColor = glm::vec4(0);
if(m_World->HasComponent(cModel.EntityID, "Fill")) { if(m_World->HasComponent(cModel.EntityID, "Fill")) {
@@ -108,7 +106,15 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
fillColor, fillColor,
fillPercentage fillPercentage
)); ));
jobs.push_back(explosionEffectJob); if(explosionEffectJob->Color.a != 1.f || explosionEffectJob->EndColor.a != 1.f || explosionEffectJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
transparentJobs.push_back(explosionEffectJob);
} else {
opaqueJobs.push_back(explosionEffectJob);
}
} else { } else {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob( std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(
model, model,
@@ -120,7 +126,14 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
fillColor, fillColor,
fillPercentage fillPercentage
)); ));
jobs.push_back(modelJob); if (modelJob->Color.a != 1.f || modelJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
transparentJobs.push_back(modelJob);
} else {
opaqueJobs.push_back(modelJob);
}
} }
} }
} }
@@ -231,7 +244,7 @@ void RenderSystem::Update(double dt)
RenderScene scene; RenderScene scene;
scene.Camera = m_Camera; scene.Camera = m_Camera;
scene.Viewport = Rectangle(1280, 720); scene.Viewport = Rectangle(1280, 720);
fillModels(scene.ForwardJobs); fillModels(scene.OpaqueObjects, scene.TransparentObjects);
fillPointLights(scene.PointLightJobs, m_World); fillPointLights(scene.PointLightJobs, m_World);
fillDirectionalLights(scene.DirectionalLightJobs, m_World); fillDirectionalLights(scene.DirectionalLightJobs, m_World);
fillText(scene.TextJobs, m_World); fillText(scene.TextJobs, m_World);
+2 -2
View File
@@ -148,14 +148,14 @@ PickData Renderer::Pick(glm::vec2 screenCoord)
void Renderer::InitializeTextures() void Renderer::InitializeTextures()
{ {
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png"); m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
} }
void Renderer::SortRenderJobsByDepth(RenderScene &scene) void Renderer::SortRenderJobsByDepth(RenderScene &scene)
{ {
//Sort all forward jobs so transparency is good. //Sort all forward jobs so transparency is good.
scene.ForwardJobs.sort(Renderer::DepthSort); scene.TransparentObjects.sort(Renderer::DepthSort);
} }
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
+16 -3
View File
@@ -47,13 +47,24 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
for (unsigned int i = 0; i < connections.length(); i++) { for (unsigned int i = 0; i < connections.length(); i++) {
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) { if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
MGlobal::select(shape.parent(i), MGlobal::kReplaceList); shape.parent(0, &status);
MGlobal::displayInfo(MString() + "Moving " + thisNode.name() + " to bindPose."); if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "shape.parent(0, &status) failed with: " + status.errorString());
}
status = MGlobal::select(shape.parent(0), MGlobal::kReplaceList);
if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "Parent to " + thisNode.name() + " failed");
}
MFnDependencyNode tmp(shape.parent(0));
MGlobal::displayInfo(MString() + "Moving " + tmp.name() + " to bindPose.");
status = MGlobal::executeCommand("GoToBindPose;"); status = MGlobal::executeCommand("GoToBindPose;");
if (status != MS::kSuccess) { if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "GoToBindPose: " + status.errorString()); MGlobal::displayError(MString() + "GoToBindPose: " + status.errorString());
} }
MGlobal::displayInfo(MString() + "Has moved " + thisNode.name() + " to bindPose.");
MGlobal::displayInfo(MString() + "Has moved " + tmp.name() + " to bindPose.");
} }
} }
} }
@@ -109,6 +120,8 @@ bool Export::Materials(std::string pathName)
bool Export::Animations(std::string pathName, std::vector<AnimationInfo> animInfo) bool Export::Animations(std::string pathName, std::vector<AnimationInfo> animInfo)
{ {
allAnimations.clear();
allBindPoses.clear();
if (MAnimControl::currentTime().unit() != MTime::kNTSCField) { if (MAnimControl::currentTime().unit() != MTime::kNTSCField) {
MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!");
+1 -3
View File
@@ -85,9 +85,6 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode&
material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1; material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1;
// Test
MGlobal::displayInfo(MString() + "getAbsolutePathToResources: " + workspace);
MGlobal::displayInfo(MString() + "Texture file: " + FullPath.c_str());
return true; return true;
} }
} }
@@ -209,6 +206,7 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
meshHasMaterial = true; meshHasMaterial = true;
MaterialStorage.IndexStart = totalIndices; MaterialStorage.IndexStart = totalIndices;
MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1; MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1;
MGlobal::displayInfo("Oh noes, breaking in material");
break; break;
} }
totalIndices += aMeshMaterial.second.size(); totalIndices += aMeshMaterial.second.size();
-2
View File
@@ -60,8 +60,6 @@ Menu::Menu(QDialog* dialog)
m_ExportPath = new QLineEdit; m_ExportPath = new QLineEdit;
m_FileDialog = new QFileDialog; m_FileDialog = new QFileDialog;
QString tmpPath("C:/Users/Nickelodion/Desktop/workspace/tacticalZ/assets/models/");
m_ExportPath->setText(tmpPath);
QLabel* exportLabel = new QLabel; QLabel* exportLabel = new QLabel;
exportLabel->setText("Export Path:"); exportLabel->setText("Export Path:");
QLabel* nameLabel = new QLabel; QLabel* nameLabel = new QLabel;
+7 -12
View File
@@ -87,10 +87,6 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
} }
weightMap[geomIter.index()] = weightInfo; weightMap[geomIter.index()] = weightInfo;
for (unsigned int k = 0; k!=nrOfWeights; k++) {
MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]);
}
geomIter.next(); geomIter.next();
} }
it.next(); it.next();
@@ -112,8 +108,6 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
MFnDependencyNode thisNode(node); MFnDependencyNode thisNode(node);
MPlugArray connections; MPlugArray connections;
thisNode.findPlug("inMesh").connectedTo(connections, true, true); thisNode.findPlug("inMesh").connectedTo(connections, true, true);
MGlobal::displayInfo(MString() + "inMesh");
bool hasSkin = false;
MPlug weightList, weights; MPlug weightList, weights;
MObject weightListObject; MObject weightListObject;
for (unsigned int i = 0; i < connections.length(); i++) { for (unsigned int i = 0; i < connections.length(); i++) {
@@ -122,7 +116,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
weightList = skinCluster.findPlug("weightList", &status); weightList = skinCluster.findPlug("weightList", &status);
weightListObject = weightList.attribute(); weightListObject = weightList.attribute();
weights = skinCluster.findPlug("weights"); weights = skinCluster.findPlug("weights");
hasSkin = true; newMesh.hasSkin = true;
break; break;
} }
} }
@@ -138,7 +132,6 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
} }
for (int pathID = 0; pathID < dagPaths.length(); pathID++) { for (int pathID = 0; pathID < dagPaths.length(); pathID++) {
MGlobal::displayInfo(dagPaths[pathID].fullPathName());
MDagPath thisMeshPath(dagPaths[pathID]); MDagPath thisMeshPath(dagPaths[pathID]);
MMatrix transformMatrix = thisMeshPath.inclusiveMatrix(&status); MMatrix transformMatrix = thisMeshPath.inclusiveMatrix(&status);
@@ -173,8 +166,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
break; break;
} }
map<string, vector<int>> materialFaceIDs; map<string, vector<int>> materialFaceIDs;
MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length());
MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length());
MPlugArray plugArray; MPlugArray plugArray;
for (int i = 0; i < shaderIndexList.length(); i++) { for (int i = 0; i < shaderIndexList.length(); i++) {
MFnDependencyNode shader(shaderList[shaderIndexList[i]]); MFnDependencyNode shader(shaderList[shaderIndexList[i]]);
@@ -308,7 +300,8 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
thisVertex.Uv[1] = UV[1]; thisVertex.Uv[1] = UV[1];
if (hasSkin) { if (newMesh.hasSkin) {
thisVertex.useWeights = true;
float totalWeight = 0.0f; float totalWeight = 0.0f;
unsigned int totalBones = 0; unsigned int totalBones = 0;
MIntArray jointIDs /* ??? */; MIntArray jointIDs /* ??? */;
@@ -326,7 +319,9 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
for (unsigned int i = 0; i < 4; i++) { for (unsigned int i = 0; i < 4; i++) {
thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight; thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight;
} }
} } else {
thisVertex.useWeights = false;
}
//float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; //float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
//if (totalWeight > 0.0001f) { //if (totalWeight > 0.0001f) {
+16 -4
View File
@@ -11,6 +11,7 @@
class VertexLayout : public OutputData class VertexLayout : public OutputData
{ {
public: public:
bool useWeights = true;
float Pos[3]{ 0 }; float Pos[3]{ 0 };
float Normal[3]{ 0 }; float Normal[3]{ 0 };
float Tangent[3]{ 0 }; float Tangent[3]{ 0 };
@@ -26,8 +27,10 @@ public:
out.write((char*)&Tangent, sizeof(float) * 3); out.write((char*)&Tangent, sizeof(float) * 3);
out.write((char*)&BiNormal, sizeof(float) * 3); out.write((char*)&BiNormal, sizeof(float) * 3);
out.write((char*)&Uv, sizeof(float) * 2); out.write((char*)&Uv, sizeof(float) * 2);
out.write((char*)&BoneIndices, sizeof(float) * 4); if (useWeights) {
out.write((char*)&BoneWeights, sizeof(float) * 4); out.write((char*)&BoneIndices, sizeof(float) * 4);
out.write((char*)&BoneWeights, sizeof(float) * 4);
}
} }
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
@@ -37,8 +40,10 @@ public:
out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl; out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl;
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl;
out << Uv[0] << " " << Uv[1] << endl; out << Uv[0] << " " << Uv[1] << endl;
out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; if (useWeights) {
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl; out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl;
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl;
}
} }
bool operator==(const VertexLayout& right) bool operator==(const VertexLayout& right)
@@ -57,6 +62,7 @@ public:
class Mesh : public OutputData { class Mesh : public OutputData {
public: public:
bool hasSkin = false;
unsigned int NumVertices; unsigned int NumVertices;
unsigned int NumIndices; unsigned int NumIndices;
std::vector<VertexLayout> Vertices; std::vector<VertexLayout> Vertices;
@@ -64,6 +70,7 @@ public:
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write((char*)&hasSkin, sizeof(bool));
out.write((char*)&NumVertices, sizeof(int)); out.write((char*)&NumVertices, sizeof(int));
out.write((char*)&NumIndices, sizeof(int)); out.write((char*)&NumIndices, sizeof(int));
for (auto aVertex : Vertices) { for (auto aVertex : Vertices) {
@@ -79,6 +86,11 @@ public:
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
{ {
out << "New Mesh _ not in binary" << endl; out << "New Mesh _ not in binary" << endl;
out << "hasSkin: ";
if(hasSkin)
out << "true" << endl;
else
out << "false" << endl;
out << "Number of vertices: " << NumVertices << endl; out << "Number of vertices: " << NumVertices << endl;
out << "number of indices: " << NumIndices << endl; out << "number of indices: " << NumIndices << endl;
int vertexNumber = 0; int vertexNumber = 0;
+277 -150
View File
@@ -60,7 +60,7 @@
// //
// return m_AllSkeletons; // return m_AllSkeletons;
//} //}
std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ" }; static std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ" };
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame) Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
{ {
@@ -68,100 +68,226 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
std::vector<MObject> animatedJoints; std::vector<MObject> animatedJoints;
std::vector<MObject> m_Hierarchy; std::vector<MObject> m_Hierarchy;
Animation returnData; Animation returnData;
double oneDivSixty = 1 / 60.0; double oneDivSixty = 1 / 60.0;
returnData.Name = animationName; returnData.Name = animationName;
returnData.nameLength = animationName.size() + 1; returnData.nameLength = animationName.size() + 1;
returnData.Duration = (endFrame - startFrame) * oneDivSixty; returnData.Duration = (endFrame - startFrame) * oneDivSixty;
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); std::map<std::string, std::array<std::array<double, 4>, 4>> joinCheckMap;
while (!jointIt.isDone()) std::map<std::string, bool> exportJoint;
{
m_Hierarchy.push_back(jointIt.item());
MFnDependencyNode depNode(jointIt.item()); //MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
for (int i = 0; i < 9; i++) //for (unsigned int i = startFrame; i <= endFrame; i++)
{ //{
MStatus tmp; // MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField));
MPlug plug = depNode.findPlug(attr[i].c_str(), &tmp); // while (!jointIt.isDone())
// {
// m_Hierarchy.push_back(jointIt.item());
MPlugArray connections; // MFnTransform MayaJoint(jointIt.item());
plug.connectedTo(connections, true, false, 0); // MMatrix transformationMatrix = MayaJoint.transformationMatrix();
for (int j = 0; j != connections.length(); j++) {
MObject connected = connections[j].node();
if (connected.hasFn(MFn::kAnimCurve)) { // if (i == startFrame)
// {
// double doubleMat[4][4];
// transformationMatrix.get(doubleMat);
MFnAnimCurve jointAnim(connected); // joinCheckMap[MayaJoint.name().asChar()][0][0] = doubleMat[0][0];
// joinCheckMap[MayaJoint.name().asChar()][0][1] = doubleMat[0][1];
// joinCheckMap[MayaJoint.name().asChar()][0][2] = doubleMat[0][2];
// joinCheckMap[MayaJoint.name().asChar()][0][3] = doubleMat[0][3];
// joinCheckMap[MayaJoint.name().asChar()][1][0] = doubleMat[1][0];
// joinCheckMap[MayaJoint.name().asChar()][1][1] = doubleMat[1][1];
// joinCheckMap[MayaJoint.name().asChar()][1][2] = doubleMat[1][2];
// joinCheckMap[MayaJoint.name().asChar()][1][3] = doubleMat[1][3];
// joinCheckMap[MayaJoint.name().asChar()][2][0] = doubleMat[2][0];
// joinCheckMap[MayaJoint.name().asChar()][2][1] = doubleMat[2][1];
// joinCheckMap[MayaJoint.name().asChar()][2][2] = doubleMat[2][2];
// joinCheckMap[MayaJoint.name().asChar()][2][3] = doubleMat[2][3];
// joinCheckMap[MayaJoint.name().asChar()][3][0] = doubleMat[3][0];
// joinCheckMap[MayaJoint.name().asChar()][3][1] = doubleMat[3][1];
// joinCheckMap[MayaJoint.name().asChar()][3][2] = doubleMat[3][2];
// joinCheckMap[MayaJoint.name().asChar()][3][3] = doubleMat[3][3];
unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp); // exportJoint[MayaJoint.name().asChar()] = false;
// }
// else if(!exportJoint[MayaJoint.name().asChar()])//!exportJoint[MayaJoint.name().asChar()])
// {
// double doubleMat[4][4];
if (tmp == MStatus::kFailure) // doubleMat[0][0] = joinCheckMap[MayaJoint.name().asChar()][0][0];
MGlobal::displayInfo(MString() + "Fail :c"); // doubleMat[0][1] = joinCheckMap[MayaJoint.name().asChar()][0][1];
// doubleMat[0][2] = joinCheckMap[MayaJoint.name().asChar()][0][2];
// doubleMat[0][3] = joinCheckMap[MayaJoint.name().asChar()][0][3];
// doubleMat[1][0] = joinCheckMap[MayaJoint.name().asChar()][1][0];
// doubleMat[1][1] = joinCheckMap[MayaJoint.name().asChar()][1][1];
// doubleMat[1][2] = joinCheckMap[MayaJoint.name().asChar()][1][2];
// doubleMat[1][3] = joinCheckMap[MayaJoint.name().asChar()][1][3];
// doubleMat[2][0] = joinCheckMap[MayaJoint.name().asChar()][2][0];
// doubleMat[2][1] = joinCheckMap[MayaJoint.name().asChar()][2][1];
// doubleMat[2][2] = joinCheckMap[MayaJoint.name().asChar()][2][2];
// doubleMat[2][3] = joinCheckMap[MayaJoint.name().asChar()][2][3];
// doubleMat[3][0] = joinCheckMap[MayaJoint.name().asChar()][3][0];
// doubleMat[3][1] = joinCheckMap[MayaJoint.name().asChar()][3][1];
// doubleMat[3][2] = joinCheckMap[MayaJoint.name().asChar()][3][2];
// doubleMat[3][3] = joinCheckMap[MayaJoint.name().asChar()][3][3];
if (startFrame * oneDivSixty <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame * oneDivSixty) { // MMatrix tmp(doubleMat);
animatedJoints.push_back(jointIt.item()); // if (!tmp.isEquivalent(transformationMatrix)) {
i = 9; // MGlobal::displayInfo(MString() + MayaJoint.name() + " is exported");
break; // exportJoint[MayaJoint.name().asChar()] = true;
} // animatedJoints.push_back(MayaJoint.object());
// }
// }
unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField)); /*for (int i = 0; i < 9; i++)
MGlobal::displayInfo(MString() + startKeyFrameIndex + " " + endKeyFrameIndex); {
MStatus tmp;
MPlug plug = depNode.findPlug(attr[i].c_str(), &tmp);
if (startFrame * oneDivSixty <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame * oneDivSixty || endKeyFrameIndex - startKeyFrameIndex > 0) { MPlugArray connections;
animatedJoints.push_back(jointIt.item()); plug.connectedTo(connections, true, false, 0);
i = 9; for (int j = 0; j != connections.length(); j++) {
break; MObject connected = connections[j].node();
}
MFnTransform MayaJoint(jointIt.item()); if (connected.hasFn(MFn::kAnimCurve)) {
MPlug BindPose = MayaJoint.findPlug("bindPose"); MFnAnimCurve jointAnim(connected);
MDataHandle DataHandle;
BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data());
MMatrix BindPoseMatrix = MartixFn.matrix();
if (!BindPoseMatrix.isEquivalent(MayaJoint.transformationMatrix())) //MGlobal::displayInfo(MString() + "curve : " + jointAnim.name());
{ //MGlobal::displayInfo(MString() + "curve keys : " + jointAnim.numKeys());
MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya"); //MGlobal::displayInfo(MString() + "curve keyframes : " + jointAnim.numKeyframes());
} //MGlobal::displayInfo(MString() + "startFrame : " + startFrame);
} //MGlobal::displayInfo(MString() + "endFrame : " + endFrame);
}
}
jointIt.next(); unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp);
}
int currentFrame = startFrame; if (tmp == MStatus::kFailure)
while (currentFrame != endFrame + 1) { // ANDREAS MGlobal::displayInfo(MString() + "Fail :c");
Animation::Keyframe thisKeyFrame;
thisKeyFrame.Index = currentFrame - startFrame;
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField)); if (startFrame * oneDivSixty <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame * oneDivSixty) {
MTime time = MAnimControl::currentTime(); //MGlobal::displayInfo(MString() + "Start key time : " + jointAnim.time(startKeyFrameIndex).value());
for (auto aJoint : animatedJoints){
MFnTransform thisJoint(aJoint);
Animation::Keyframe::JointProperty joint;
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), thisJoint.object()); if (startFrame <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame ) {
if (it != m_Hierarchy.end()) { animatedJoints.push_back(jointIt.item());
joint.ID = it - m_Hierarchy.begin(); i = 9;
} break;
else { }
MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name());
} unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField));
MGlobal::displayInfo(MString() + startKeyFrameIndex + " " + endKeyFrameIndex);
MTransformationMatrix Matrix = thisJoint.transformation(); MGlobal::displayInfo(MString() + "Fail!!!!!!!!!!!!!!!!!!!!!!!!!");
if (startFrame * oneDivSixty <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame * oneDivSixty || endKeyFrameIndex - startKeyFrameIndex > 0) {
//MGlobal::displayInfo(MString() + "End key index : " + endKeyFrameIndex);
//MGlobal::displayInfo(MString() + "end key time : " + jointAnim.time(endKeyFrameIndex).value());
/*MGlobal::displayInfo(MString() + "start keyfram index: " + startKeyFrameIndex + ". End keyfram index: " + endKeyFrameIndex + ".");*/
/*if (startFrame <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame || endKeyFrameIndex - startKeyFrameIndex > 0) {
animatedJoints.push_back(jointIt.item());
i = 9;
break;
}
MFnTransform MayaJoint(jointIt.item());
MPlug BindPose = MayaJoint.findPlug("bindPose");
MDataHandle DataHandle;
BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data());
MMatrix BindPoseMatrix = MartixFn.matrix();
if (!BindPoseMatrix.isEquivalent(MayaJoint.transformationMatrix()))
{
MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya");
}
}
}
}
} // end of int i loop*/
/* jointIt.next();
}
jointIt.reset();
}*/
int currentFrame = startFrame;
while (currentFrame <= endFrame) { // ANDREAS
Animation::Keyframe thisKeyFrame;
thisKeyFrame.Index = currentFrame - startFrame;
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
MTime time = MAnimControl::currentTime();
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
unsigned int jointID = 0;
while (!jointIt.isDone()) {
MFnTransform thisJoint(jointIt.currentItem());
MMatrix transformationMatrix = thisJoint.transformationMatrix();
double doubleMat[4][4];
if (currentFrame != startFrame){
Animation::Keyframe::JointProperty joint;
doubleMat[0][0] = joinCheckMap[thisJoint.name().asChar()][0][0];
doubleMat[0][1] = joinCheckMap[thisJoint.name().asChar()][0][1];
doubleMat[0][2] = joinCheckMap[thisJoint.name().asChar()][0][2];
doubleMat[0][3] = joinCheckMap[thisJoint.name().asChar()][0][3];
doubleMat[1][0] = joinCheckMap[thisJoint.name().asChar()][1][0];
doubleMat[1][1] = joinCheckMap[thisJoint.name().asChar()][1][1];
doubleMat[1][2] = joinCheckMap[thisJoint.name().asChar()][1][2];
doubleMat[1][3] = joinCheckMap[thisJoint.name().asChar()][1][3];
doubleMat[2][0] = joinCheckMap[thisJoint.name().asChar()][2][0];
doubleMat[2][1] = joinCheckMap[thisJoint.name().asChar()][2][1];
doubleMat[2][2] = joinCheckMap[thisJoint.name().asChar()][2][2];
doubleMat[2][3] = joinCheckMap[thisJoint.name().asChar()][2][3];
doubleMat[3][0] = joinCheckMap[thisJoint.name().asChar()][3][0];
doubleMat[3][1] = joinCheckMap[thisJoint.name().asChar()][3][1];
doubleMat[3][2] = joinCheckMap[thisJoint.name().asChar()][3][2];
doubleMat[3][3] = joinCheckMap[thisJoint.name().asChar()][3][3];
MMatrix LastJointMatrix(doubleMat);
//Is same as last KeyFrame
if (LastJointMatrix.isEquivalent(transformationMatrix)) {
jointID++;
jointIt.next();
continue;
}
}
transformationMatrix.get(doubleMat);
joinCheckMap[thisJoint.name().asChar()][0][0] = doubleMat[0][0];
joinCheckMap[thisJoint.name().asChar()][0][1] = doubleMat[0][1];
joinCheckMap[thisJoint.name().asChar()][0][2] = doubleMat[0][2];
joinCheckMap[thisJoint.name().asChar()][0][3] = doubleMat[0][3];
joinCheckMap[thisJoint.name().asChar()][1][0] = doubleMat[1][0];
joinCheckMap[thisJoint.name().asChar()][1][1] = doubleMat[1][1];
joinCheckMap[thisJoint.name().asChar()][1][2] = doubleMat[1][2];
joinCheckMap[thisJoint.name().asChar()][1][3] = doubleMat[1][3];
joinCheckMap[thisJoint.name().asChar()][2][0] = doubleMat[2][0];
joinCheckMap[thisJoint.name().asChar()][2][1] = doubleMat[2][1];
joinCheckMap[thisJoint.name().asChar()][2][2] = doubleMat[2][2];
joinCheckMap[thisJoint.name().asChar()][2][3] = doubleMat[2][3];
joinCheckMap[thisJoint.name().asChar()][3][0] = doubleMat[3][0];
joinCheckMap[thisJoint.name().asChar()][3][1] = doubleMat[3][1];
joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2];
joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3];
MTransformationMatrix Matrix = thisJoint.transformation();
MPlug BindPose = thisJoint.findPlug("bindPose"); MPlug BindPose = thisJoint.findPlug("bindPose");
MDataHandle DataHandle; MDataHandle DataHandle;
BindPose.getValue(DataHandle); BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data()); MFnMatrixData MartixFn(DataHandle.data());
MMatrix BindPoseMatrix = MartixFn.matrix(); MMatrix BindPoseMatrix = MartixFn.matrix();
Matrix = Matrix.asMatrix(); Matrix = Matrix.asMatrix();
MObject jointOrientObj = thisJoint.attribute("jointOrient"); MObject jointOrientObj = thisJoint.attribute("jointOrient");
MFnNumericAttribute jointOrient(jointOrientObj); MFnNumericAttribute jointOrient(jointOrientObj);
double jointOrientDouble[3]; double jointOrientDouble[3];
@@ -175,95 +301,96 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MEulerRotation joEuler(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]); MEulerRotation joEuler(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]);
MQuaternion jo = joEuler.asQuaternion(); MQuaternion jo = joEuler.asQuaternion();
double tmp[4]; double tmp[4];
Matrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); Matrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
MQuaternion rotation(tmp); MQuaternion rotation(tmp);
rotation = rotation * jo; rotation = rotation * jo;
rotation.get(tmp); rotation.get(tmp);
joint.Rotation[0] = tmp[0]; Animation::Keyframe::JointProperty joint;
joint.Rotation[1] = tmp[1]; joint.ID = jointID;
joint.Rotation[2] = tmp[2];
joint.Rotation[3] = tmp[3];
Matrix.getTranslation(MSpace::kTransform).get(tmp);
joint.Position[0] = tmp[0];
joint.Position[1] = tmp[1];
joint.Position[2] = tmp[2];
Matrix.getScale(tmp, MSpace::kTransform);
joint.Scale[0] = tmp[0];
joint.Scale[1] = tmp[1];
joint.Scale[2] = tmp[2];
thisKeyFrame.JointProperties.push_back(joint); joint.Rotation[0] = tmp[0];
} joint.Rotation[1] = tmp[1];
returnData.Keyframes.push_back(thisKeyFrame); joint.Rotation[2] = tmp[2];
currentFrame++; joint.Rotation[3] = tmp[3];
} Matrix.getTranslation(MSpace::kTransform).get(tmp);
joint.Position[0] = tmp[0];
joint.Position[1] = tmp[1];
joint.Position[2] = tmp[2];
Matrix.getScale(tmp, MSpace::kTransform);
joint.Scale[0] = tmp[0];
joint.Scale[1] = tmp[1];
joint.Scale[2] = tmp[2];
thisKeyFrame.JointProperties.push_back(joint);
jointID++;
jointIt.next();
}
thisKeyFrame.NumberOfJoints = thisKeyFrame.JointProperties.size();
returnData.Keyframes.push_back(thisKeyFrame);
currentFrame++;
}
returnData.NumKeyFrames = returnData.Keyframes.size(); returnData.NumKeyFrames = returnData.Keyframes.size();
returnData.NumberOfJoints = animatedJoints.size();
return returnData; return returnData;
} }
std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses() std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
{ {
MStatus status; MStatus status;
std::vector<BindPoseSkeletonNode> m_AllSkeletons; std::vector<BindPoseSkeletonNode> m_AllSkeletons;
std::vector<MObject> m_Hierarchy; std::vector<MObject> m_Hierarchy;
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
BindPoseSkeletonNode SkeletonStorage; BindPoseSkeletonNode SkeletonStorage;
while (!jointIt.isDone()) { while (!jointIt.isDone()) {
MFnTransform MayaJoint(jointIt.currentItem()); MFnTransform MayaJoint(jointIt.currentItem());
BindPoseSkeletonNode::BindPoseJoint NewJoint; BindPoseSkeletonNode::BindPoseJoint NewJoint;
if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") { if (MFnDependencyNode(MayaJoint.parent(0)).object().apiType() != MFn::kJoint) {
if (SkeletonStorage.Joints.size() != 0) { if (SkeletonStorage.Joints.size() != 0) {
m_AllSkeletons.push_back(SkeletonStorage); m_AllSkeletons.push_back(SkeletonStorage);
SkeletonStorage.Joints.clear(); SkeletonStorage.Joints.clear();
SkeletonStorage.Name.clear(); SkeletonStorage.Name.clear();
} }
SkeletonStorage.Name = std::string(MayaJoint.name().asChar()); SkeletonStorage.Name = std::string(MayaJoint.name().asChar());
NewJoint.ParentID = -1; // This joint is root NewJoint.ParentID = -1; // This joint is root
} } else {
else { auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0));
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0)); if (it != m_Hierarchy.end()) {
if (it != m_Hierarchy.end()) { NewJoint.ParentID = it - m_Hierarchy.begin();
NewJoint.ParentID = it - m_Hierarchy.begin(); } else {
} MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name());
else { }
MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name()); }
} m_Hierarchy.push_back(MayaJoint.object());
}
m_Hierarchy.push_back(MayaJoint.object());
MPlug BindPose = MayaJoint.findPlug("bindPose", &status); MPlug BindPose = MayaJoint.findPlug("bindPose", &status);
if (status != MS::kSuccess) { if (status != MS::kSuccess) {
MGlobal::displayError(MString() + "Could not find bindPose plug: " + status.errorString()); MGlobal::displayError(MString() + "Could not find bindPose plug: " + status.errorString());
} }
MDataHandle DataHandle; MDataHandle DataHandle;
BindPose.getValue(DataHandle); BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data()); MFnMatrixData MartixFn(DataHandle.data());
MMatrix Matrix = MartixFn.matrix(); MMatrix Matrix = MartixFn.matrix();
MVector tmp = MayaJoint.transformation().getTranslation(MSpace::kObject); MVector tmp = MayaJoint.transformation().getTranslation(MSpace::kObject);
MGlobal::displayError(MString() + "translation befor: " + tmp[0] + " " + tmp[1] + " " + tmp[2]);
//Matrix[3][0] *= -1; //Matrix[3][0] *= -1;
//Matrix[3][2] *= -1; //Matrix[3][2] *= -1;
//Matrix[3][1] *= -1; //Matrix[3][1] *= -1;
double test[3]; double test[3];
MayaJoint.transformation().getScale(test, MSpace::kObject); MayaJoint.transformation().getScale(test, MSpace::kObject);
MGlobal::displayError(MString() + "scale: " + test[0] + " " + test[1] + " " + test[2]);
MTransformationMatrix::RotationOrder order = MTransformationMatrix::RotationOrder::kXYZ; MTransformationMatrix::RotationOrder order = MTransformationMatrix::RotationOrder::kXYZ;
MayaJoint.transformation().getRotation(test, order); MayaJoint.transformation().getRotation(test, order);
MGlobal::displayError(MString() + "rotation: " + test[0] + " " + test[1] + " " + test[2]);
//----- test //----- test
@@ -310,33 +437,33 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
Matrix = Matrix.inverse(); Matrix = Matrix.inverse();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
} }
} }
NewJoint.Name = MayaJoint.name().asChar(); NewJoint.Name = MayaJoint.name().asChar();
NewJoint.NameLength = MayaJoint.name().length() + 1; NewJoint.NameLength = MayaJoint.name().length() + 1;
NewJoint.ID = SkeletonStorage.Joints.size(); NewJoint.ID = SkeletonStorage.Joints.size();
//double tmp[3]; //double tmp[3];
//((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); //((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp);
//NewJoint.Rotation[0] = tmp[0]; //NewJoint.Rotation[0] = tmp[0];
//NewJoint.Rotation[1] = tmp[1]; //NewJoint.Rotation[1] = tmp[1];
//NewJoint.Rotation[2] = tmp[2]; //NewJoint.Rotation[2] = tmp[2];
//((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform); //((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform);
//NewJoint.Scale[0] = tmp[0]; //NewJoint.Scale[0] = tmp[0];
//NewJoint.Scale[1] = tmp[1]; //NewJoint.Scale[1] = tmp[1];
//NewJoint.Scale[2] = tmp[2]; //NewJoint.Scale[2] = tmp[2];
//((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp); //((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp);
//NewJoint.Translation[0] = tmp[0]; //NewJoint.Translation[0] = tmp[0];
//NewJoint.Translation[1] = tmp[1]; //NewJoint.Translation[1] = tmp[1];
//NewJoint.Translation[2] = tmp[2]; //NewJoint.Translation[2] = tmp[2];
SkeletonStorage.Joints.push_back(NewJoint); SkeletonStorage.Joints.push_back(NewJoint);
SkeletonStorage.numBones++; SkeletonStorage.numBones++;
jointIt.next(); jointIt.next();
} }
m_AllSkeletons.push_back(SkeletonStorage); m_AllSkeletons.push_back(SkeletonStorage);
return m_AllSkeletons; return m_AllSkeletons;
} }
+5 -4
View File
@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <array> #include <array>
#include <map>
#include <algorithm> #include <algorithm>
#include "MayaIncludes.h" #include "MayaIncludes.h"
#include "OutputData.h" #include "OutputData.h"
@@ -21,6 +22,7 @@ public:
int Index = 0; int Index = 0;
float Time = 0; float Time = 0;
int NumberOfJoints;
std::vector<JointProperty> JointProperties; std::vector<JointProperty> JointProperties;
}; };
@@ -28,7 +30,6 @@ public:
int nameLength = 0; int nameLength = 0;
float Duration = 0; float Duration = 0;
int NumKeyFrames = 0; int NumKeyFrames = 0;
int NumberOfJoints = 0;
std::vector<Keyframe> Keyframes; std::vector<Keyframe> Keyframes;
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
@@ -37,11 +38,11 @@ public:
out.write(Name.c_str(), Name.size() + 1); out.write(Name.c_str(), Name.size() + 1);
out.write((char*)&Duration, sizeof(float)); out.write((char*)&Duration, sizeof(float));
out.write((char*)&NumKeyFrames, sizeof(int)); out.write((char*)&NumKeyFrames, sizeof(int));
out.write((char*)&NumberOfJoints, sizeof(int));
//Här under loopas alla key frames igenom //Här under loopas alla key frames igenom
for (auto aKeyframe : Keyframes) { for (auto aKeyframe : Keyframes) {
out.write((char*)&aKeyframe.Index, sizeof(int)); out.write((char*)&aKeyframe.Index, sizeof(int));
out.write((char*)&aKeyframe.Time, sizeof(float)); out.write((char*)&aKeyframe.Time, sizeof(float));
out.write((char*)&aKeyframe.NumberOfJoints, sizeof(int));
for (auto aJoint : aKeyframe.JointProperties) { for (auto aJoint : aKeyframe.JointProperties) {
out.write((char*)&aJoint.ID, sizeof(int)); out.write((char*)&aJoint.ID, sizeof(int));
out.write((char*)aJoint.Position, sizeof(float) * 3); out.write((char*)aJoint.Position, sizeof(float) * 3);
@@ -55,11 +56,11 @@ public:
{ {
out << "Animation Name: " << Name << endl; out << "Animation Name: " << Name << endl;
out << "Duration: " << Duration << endl; out << "Duration: " << Duration << endl;
out << "Number of KeyFrames: " << NumKeyFrames << endl; out << "Number of KeyFrames: " << NumKeyFrames << endl;
out << "Number of Joints: " << NumberOfJoints << endl;
for (auto aKeyframe : Keyframes) { for (auto aKeyframe : Keyframes) {
out << "Frame: " << aKeyframe.Index << endl; out << "Frame: " << aKeyframe.Index << endl;
out << "Time: " << aKeyframe.Time << endl; out << "Time: " << aKeyframe.Time << endl;
out << "Number of Joints: " << aKeyframe.NumberOfJoints << endl;
for (auto aJoint : aKeyframe.JointProperties) { for (auto aJoint : aKeyframe.JointProperties) {
out << "Joint ID: " << aJoint.ID << endl; out << "Joint ID: " << aJoint.ID << endl;
out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl; out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl;