Custom Animations should now work. We also save color values if there's no texture.

This commit is contained in:
antc13
2016-01-24 13:28:40 +01:00
parent 3baa988ad4
commit b5b1140f5c
11 changed files with 341 additions and 28 deletions
@@ -48,6 +48,9 @@ public:
{
float SpecularExponent;
float ReflectionFactor;
float DiffuseColor[3];
float SpecularColor[3];
float IncandescenceColor[3];
unsigned int StartIndex;
unsigned int EndIndex;
//float Transparency;
+273
View File
@@ -0,0 +1,273 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Camera/>
<c:Listener/>
<c:Transform>
<Position X="4.52910185" Y="5.50171423" Z="7.69566345"/>
<Orientation X="-0.453785568" Y="0.436270237" Z="-1.03594937e-06"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/dummyscene.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0" Y="-0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/animtest.</Resource>
</c:Model>
<c:Transform>
<Position X="-0.0966923237" Y="1.2939688" Z="0.399702221"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/animTest.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0" Y="1.31816244" Z="1.1888907"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/animTest.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.708824873" Y="1.30000007" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/animTest.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="1.36948848" Y="1.20000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:DirectionalLight>
<Intensity>0.13000047206878662</Intensity>
</c:DirectionalLight>
<c:Transform>
<Position X="0" Y="2.77622533" Z="0"/>
<Orientation X="0" Y="1.30900002" Z="1.73600006"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:RaptorCopter>
<Speed>0.30000001192092896</Speed>
<Axis X="0" Y="5" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="117.03714" Y="3023.50244" Z="3.03297734"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="1" G="1" R="0"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="0" Y="1" Z="1.29999995"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0" G="1" R="0"/>
<Radius>5</Radius>
<Intensity>0.80000001192092896</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0" Y="1" Z="-1.29999995"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="1" G="0" R="0.478431374"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="-1.30000007" Y="1" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0" G="1" R="1"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="1.29999995" Y="1" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:RaptorCopter>
<Speed>0.50999981164932251</Speed>
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Position X="0" Y="-0.100000001" Z="0"/>
<Orientation X="0" Y="191.457993" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0.301960796" G="0.0901960805" R="0.247058824"/>
<Radius>5</Radius>
<Intensity>5</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0" Y="3" Z="5"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0.960784316" G="1" R="0"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="0" Y="3" Z="-7.66608238"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0.00784313772" G="1" R="1"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="-3.47176075" Y="3" Z="-8.09415054"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0" G="0" R="1"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="-9.50536728" Y="2" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="1" G="0" R="1"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="0" Y="3" Z="4.40877533"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0.431372553" G="0.0745098069" R="1"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="5.83008432" Y="3" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0" G="0.623529434" R="0.929411769"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="3.72500014" Y="3" Z="-4.26100016"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="0" Y="3" Z="-7.50000048"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight>
<Color A="1" B="0.192156866" G="1" R="0"/>
<Radius>5</Radius>
</c:PointLight>
<c:Transform>
<Position X="-5.90153885" Y="3" Z="-5.40681458"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+1 -1
View File
@@ -24,7 +24,7 @@ void main()
mat4 boneTransform = mat4(1);
if(BoneWeights[0] > 0.f){
if(BoneWeights[0] > 0.0f){
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
+3 -3
View File
@@ -21,7 +21,7 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ForwardPlusProgram->Compile();
m_ForwardPlusProgram->Link();
}
static double tempTime = 0.0;
void DrawFinalPass::Draw(RenderScene& scene)
{
GLERROR("DrawFinalPass::Draw: Pre");
@@ -53,14 +53,14 @@ void DrawFinalPass::Draw(RenderScene& scene)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
tempTime += 0.01f;
//TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :)
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running");
if (animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones(
*animation,
1.0f
tempTime
);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
+9 -6
View File
@@ -129,8 +129,8 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un
unsigned int* nameLengths = (unsigned int*)(fileData + offset);
offset += sizeof(unsigned int) * 4;
if (offset + sizeof(float) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material specular and reflection values failed");
if (offset + sizeof(float) * 11 + sizeof(unsigned int) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material specular, reflection, color and start and end index values failed");
}
newMaterial.SpecularExponent = *(float*)(fileData + offset);
@@ -138,9 +138,12 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un
newMaterial.ReflectionFactor = *(float*)(fileData + offset);
offset += sizeof(float);
if (offset + sizeof(unsigned int) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material start and end index values failed");
}
memcpy(newMaterial.DiffuseColor, fileData + offset, sizeof(float) * 3);
offset += sizeof(float) * 3;
memcpy(newMaterial.SpecularColor, fileData + offset, sizeof(float) * 3);
offset += sizeof(float) * 3;
memcpy(newMaterial.IncandescenceColor, fileData + offset, sizeof(float) * 3);
offset += sizeof(float) * 3;
newMaterial.StartIndex = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
@@ -202,7 +205,7 @@ void RawModelCustom::ReadAnimationFile(std::string filePath)
if (!in.is_open()) {
//throw Resource::FailedLoadingException("Open animation file failed");
return; // AJABAJA!!!!!!!!
return;
}
unsigned int fileByteSize = in.tellg();
+20 -10
View File
@@ -5,23 +5,30 @@ void Material::grabLambertProperties(MaterialNode& material_node, MFnDependencyN
material_node.Name = node.name().asChar();
if (!findColorTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no color texture. Please apply a texture insted of using a value");
node.findPlug("colorR").getValue(material_node.DiffuseColor[0]);
node.findPlug("colorG").getValue(material_node.DiffuseColor[1]);
node.findPlug("colorB").getValue(material_node.DiffuseColor[2]);
}
if (findIncandescenceTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no Incandescence texture. Please apply a texture insted of using value");
if (!findIncandescenceTexture(material_node, node)) {
node.findPlug("incandescenceR").getValue(material_node.IncandescenceColor[0]);
node.findPlug("incandescenceG").getValue(material_node.IncandescenceColor[1]);
node.findPlug("incandescenceB").getValue(material_node.IncandescenceColor[2]);
}
if (findNormalTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture. Please apply a texture to it");
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture.");
}
}
void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node)
{
if (findSpecularTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it");
if (!findSpecularTexture(material_node, node)) {
node.findPlug("specularColorR").getValue(material_node.SpecularColor[0]);
node.findPlug("specularColorG").getValue(material_node.SpecularColor[1]);
node.findPlug("specularColorB").getValue(material_node.SpecularColor[2]);
}
m_Plug = node.findPlug("reflectivity");
@@ -43,8 +50,10 @@ void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNod
void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node)
{
if (findSpecularTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it");
if (!findSpecularTexture(material_node, node)) {
node.findPlug("specularColorR").getValue(material_node.SpecularColor[0]);
node.findPlug("specularColorG").getValue(material_node.SpecularColor[1]);
node.findPlug("specularColorB").getValue(material_node.SpecularColor[2]);
}
m_Plug = node.findPlug("reflectivity");
@@ -188,20 +197,21 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
// All materials we care about inherit from Lambert
MItDependencyNodes matIt(MFn::kLambert);
m_AllMaterials.clear();
int totalIndices = 0;
while (!matIt.isDone()) {
MFnDependencyNode MaterialFnDN(matIt.thisNode());
MaterialNode MaterialStorage;
bool meshHasMaterial = false;
//Mesh Indices is a map with <string : MaterialName, vector<int> : indices>
int totalIndices = 0;
for (auto aMeshMaterial : mesh.Indices) {
MGlobal::displayInfo(MString() + "Material: " + aMeshMaterial.first.c_str() + " " + MaterialFnDN.name().asChar());
if (aMeshMaterial.first.compare(MaterialFnDN.name().asChar()) == 0) {
meshHasMaterial = true;
MaterialStorage.IndexStart = totalIndices;
MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1;
totalIndices += aMeshMaterial.second.size();
break;
}
totalIndices += aMeshMaterial.second.size();
}
if (meshHasMaterial) {
grabLambertProperties(MaterialStorage, MaterialFnDN);
@@ -19,15 +19,18 @@ public:
float ReflectionFactor;
float SpecularExponent;
float DiffuseColor[3]{ 1.0f };
unsigned int ColorMapFileLength = 0;
std::string ColorMapFile;
float SpecularColor[3]{ 1.0f };
unsigned int SpecularMapFileLength = 0;
std::string SpecularMapFile;
unsigned int NormalMapFileLength = 0;
std::string NormalMapFile;
float IncandescenceColor[3]{ 1.0f };
unsigned int IncandescenceMapFileLength = 0;
std::string IncandescenceMapFile;
@@ -43,6 +46,9 @@ public:
out.write((char*)&SpecularExponent, sizeof(float));
out.write((char*)&ReflectionFactor, sizeof(float));
out.write((char*)&DiffuseColor, sizeof(float) * 3);
out.write((char*)&SpecularColor, sizeof(float) * 3);
out.write((char*)&IncandescenceColor, sizeof(float) * 3);
out.write((char*)&IndexStart, sizeof(unsigned int));
out.write((char*)&IndexEnd, sizeof(unsigned int));
@@ -64,6 +70,9 @@ public:
out << "SpecularExponent: " << SpecularExponent << endl;
out << "ReflectionFactor: " << ReflectionFactor << endl;
out << "DiffuseColor: " << DiffuseColor[0] << " " << DiffuseColor[1] << " " << DiffuseColor[2] << endl;
out << "SpecularColor: " << SpecularColor[0] << " " << SpecularColor[1] << " " << SpecularColor[2] << endl;
out << "IncandescenceColor: " << IncandescenceColor[0] << " " << IncandescenceColor[1] << " " << IncandescenceColor[2] << endl;
out << "IndexStart: " << IndexStart << endl;
out << "IndexEnd: " << IndexEnd << endl;
+4 -3
View File
@@ -104,9 +104,10 @@ Menu::Menu(QDialog* dialog)
// Set the layout for our window
dialog->setLayout(baseLayout);
for (unsigned int i = 0; i < 3; i++) {
this->AddClipClicked(true);
}
this->AddClipClicked(true);
//for (unsigned int i = 0; i < 3; i++) {
// this->AddClipClicked(true);
//}
}
+12 -2
View File
@@ -309,12 +309,22 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
if (hasSkin) {
float totalWeight = 0.0f;
unsigned int totalBones = 0;
MIntArray jointIDs /* ??? */;
weights.selectAncestorLogicalIndex(vertexIndex, weightListObject);
weights.getExistingArrayAttributeIndices(jointIDs);
for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) {
thisVertex.BoneIndices[i] = jointIDs[i];
thisVertex.BoneWeights[i] = weights[i].asFloat();
if (weights[i].asFloat() > 0.001f) {
thisVertex.BoneIndices[totalBones] = jointIDs[i];
thisVertex.BoneWeights[totalBones] = weights[i].asFloat();
totalWeight = totalWeight + weights[i].asFloat();
totalBones++;
}
}
for (unsigned int i = 0; i < 4; i++) {
thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight;
}
}
@@ -25,10 +25,13 @@ bool WriteToFile::ASCIIFilePath(string filePathAndFileName)
void WriteToFile::OpenFiles()
{
if (binFile)
binFile.open(binFileName, ofstream::binary);
if (ASCIIFile)
if (binFile) {
binFile.open(binFileName, ofstream::binary);
}
if (ASCIIFile){
ASCIIFile.open(ASCIIFileName);
ASCIIFile << std::fixed << std::setprecision(3);
}
}
void WriteToFile::CloseFiles()
@@ -5,6 +5,7 @@
#include "OutputData.h"
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;