Importing custom mesh without material.

This commit is contained in:
antc13
2016-01-18 19:37:55 +01:00
parent 16c39df439
commit 2a3009212a
21 changed files with 402 additions and 248 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
#include "../Core/Ray.h"
#include "../Core/AABB.h"
#include "Engine/Rendering/RawModelAssimp.h"
//#include "Engine/Rendering/RawModelAssimp.h"
#include "Engine/Rendering/RawModelCustom.h"
#include "../Core/Entity.h"
class World;
+4 -4
View File
@@ -32,10 +32,10 @@ public:
};
struct FailedLoadingException : public std::exception
{
virtual const char* what() const throw()
{
return "Resource is failed to load.";
}
FailedLoadingException(char const* const _Message)
: std::exception(_Message)
{ }
FailedLoadingException() :std::exception("Resource failed to load.") { };
};
// Pretend that this is a pure virtual function that you have to implement
+1 -3
View File
@@ -1,7 +1,7 @@
#ifndef Model_h__
#define Model_h__
#include "RawModelAssimp.h"
#include "RawModelCustom.h"
#include "../OpenGL.h"
class Model : public ThreadUnsafeResource
@@ -23,8 +23,6 @@ public:
private:
RawModel* m_RawModel;
GLuint VertexBuffer;
GLuint DiffuseVertexColorBuffer;
GLuint SpecularVertexColorBuffer;
GLuint NormalBuffer;
GLuint TangentNormalsBuffer;
GLuint BiTangentNormalsBuffer;
+16 -9
View File
@@ -40,15 +40,22 @@ public:
struct MaterialGroup
{
float Shininess;
std::shared_ptr<::Texture> Texture;
std::shared_ptr<::Texture> NormalMap;
std::shared_ptr<::Texture> SpecularMap;
float SpecularExponent;
float ReflectionFactor;
unsigned int StartIndex;
unsigned int EndIndex;
//float Transparency;
std::string TexturePath;
std::shared_ptr<::Texture> Texture;
std::string NormalMapPath;
std::shared_ptr<::Texture> NormalMap;
std::string SpecularMapPath;
std::shared_ptr<::Texture> SpecularMap;
std::string IncandescenceMapPath;
std::shared_ptr<::Texture> IncandescenceMap;
};
std::vector<MaterialGroup> TextureGroups;
std::vector<MaterialGroup> MaterialGroups;
std::vector<Vertex> m_Vertices;
std::vector<unsigned int> m_Indices;
@@ -57,10 +64,10 @@ public:
private:
bool ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
bool ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
bool ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
bool ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
void ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
void ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
void ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
};
+30
View File
@@ -0,0 +1,30 @@
<?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>
<Orientation X="0" Y="-0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>models/coolTriangle.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+3 -8
View File
@@ -9,18 +9,14 @@ layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 Tangent;
layout(location = 3) in vec3 BiTangent;
layout(location = 4) in vec2 TextureCoords;
layout(location = 5) in vec4 DiffuseVertexColor;
layout(location = 6) in vec4 SpecularVertexColor;
layout(location = 7) in vec4 BoneIndices1;
layout(location = 8) in vec4 BoneIndices2;
layout(location = 9) in vec4 BoneWeights1;
layout(location = 10) in vec4 BoneWeights2;
layout(location = 5) in vec4 BoneIndices;
layout(location = 6) in vec4 BoneWeights;
out VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
}Output;
void main()
@@ -30,5 +26,4 @@ void main()
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
Output.Normal = Normal;
Output.DiffuseColor = DiffuseVertexColor;
}
+2 -3
View File
@@ -44,7 +44,6 @@ in VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
}Input;
out vec4 fragmentColor;
@@ -114,7 +113,7 @@ void main()
totalLighting.Specular += result.Specular;
}
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
//fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
//fragmentColor = texel * Input.DiffuseColor * Color;
@@ -126,7 +125,7 @@ void main()
}
fragmentColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
+2 -8
View File
@@ -9,18 +9,13 @@ layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 Tangent;
layout(location = 3) in vec3 BiTangent;
layout(location = 4) in vec2 TextureCoords;
layout(location = 5) in vec4 DiffuseVertexColor;
layout(location = 6) in vec4 SpecularVertexColor;
layout(location = 7) in vec4 BoneIndices1;
layout(location = 8) in vec4 BoneIndices2;
layout(location = 9) in vec4 BoneWeights1;
layout(location = 10) in vec4 BoneWeights2;
layout(location = 5) in vec4 BoneIndices;
layout(location = 6) in vec4 BoneWeights;
out VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
}Output;
void main()
@@ -30,5 +25,4 @@ void main()
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
Output.Normal = Normal;
Output.DiffuseColor = DiffuseVertexColor;
}
+13 -13
View File
@@ -291,21 +291,21 @@ void EditorSystem::createWidget()
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
m_World->AttachComponent(m_WidgetPlaneX, "Model");
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneX.obj";
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh";
m_WidgetY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetY, "Transform");
m_World->AttachComponent(m_WidgetY, "Model");
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
m_World->AttachComponent(m_WidgetPlaneY, "Model");
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneY.obj";
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh";
m_WidgetZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetZ, "Transform");
m_World->AttachComponent(m_WidgetZ, "Model");
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj";
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh";
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetOrigin, "Transform");
m_World->AttachComponent(m_WidgetOrigin, "Model");
@@ -350,9 +350,9 @@ void EditorSystem::setWidgetMode(WidgetMode newMode)
m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = false;
if (newMode == WidgetMode::Translate) {
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj";
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj";
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj";
//m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj";
//m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj";
//m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj";
// Temporarily disabled for local space until I can figure out what's wrong with the math
if (m_WidgetSpace != WidgetSpace::Local) {
m_World->GetComponent(m_WidgetPlaneX, "Model")["Visible"] = true;
@@ -366,19 +366,19 @@ void EditorSystem::setWidgetMode(WidgetMode newMode)
}
}
} else if (newMode == WidgetMode::Scale) {
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj";
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj";
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj";
//m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj";
//m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj";
//m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj";
m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = true;
m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj";
//m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj";
if (m_Selection != EntityID_Invalid) {
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection));
}
} else if (newMode == WidgetMode::Rotate) {
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj";
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj";
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj";
//m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj";
//m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj";
//m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj";
if (m_Selection != EntityID_Invalid) {
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
if (m_WidgetSpace == WidgetSpace::Local) {
-3
View File
@@ -74,9 +74,6 @@ RawModel::RawModel(std::string fileName)
auto uv = mesh->mTextureCoords[0][vertexIndex];
desc.TextureCoords = glm::vec2(uv.x, uv.y);
}
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity);
m_Vertices.push_back(desc);
}
+36 -18
View File
@@ -2,16 +2,12 @@
RawModel::RawModel(std::string fileName)
{
boost::endian::big_int16_buf_t* test;
int16_t tal;
test = &(boost::endian::big_int16_buf_t)tal;
char* fileData;
std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate);
if (!in.is_open())
LOG_ERROR("Failed to load custom binary model \"%s\"", fileName.c_str());
if (!in.is_open()) {
throw Resource::FailedLoadingException("Open file failed");
}
unsigned int fileByteSize = in.tellg();
in.seekg(0, std::ios_base::beg);
@@ -20,42 +16,64 @@ RawModel::RawModel(std::string fileName)
in.close();
unsigned int offset = 0;
ReadMeshFileHeader(offset, fileData, fileByteSize);
ReadMesh(offset, fileData, fileByteSize);
if (fileByteSize > 0) {
ReadMeshFileHeader(offset, fileData, fileByteSize);
ReadMesh(offset, fileData, fileByteSize);
}
delete fileData;
MaterialGroup mat;
mat.StartIndex = 0;
mat.EndIndex = m_Indices.size() - 1;
MaterialGroups.push_back(mat);
}
bool RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
#ifdef BOOST_LITTLE_ENDIAN
m_Vertices.resize(*fileData);
unsigned int test;
test = *(unsigned int*)fileData;
unsigned int* test2;
test2 = (unsigned int*)fileData;
m_Vertices.resize(test);
offset += sizeof(unsigned int);
m_Indices.resize(*(fileData + offset));
test = *(unsigned int*)(fileData + offset);
m_Indices.resize(*(unsigned int*)(fileData + offset));
offset += sizeof(unsigned int);
#else
#endif
}
bool RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
void RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
ReadVertices(offset, fileData, fileByteSize);
ReadIndices(offset, fileData, fileByteSize);
}
bool RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
#ifdef BOOST_LITTLE_ENDIAN
memcpy(&m_Vertices[0], fileData, m_Vertices.size() * sizeof(Vertex));
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
throw Resource::FailedLoadingException("Reading vertices failed");
}
unsigned int i = sizeof(Vertex);
unsigned int ii = sizeof(unsigned int);
memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex));
offset += m_Vertices.size() * sizeof(Vertex);
#else
#endif
}
bool RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
#ifdef BOOST_LITTLE_ENDIAN
memcpy(&m_Indices[0], fileData, m_Indices.size() * sizeof(unsigned int));
if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) {
throw Resource::FailedLoadingException("Reading indices failed");
}
memcpy(&m_Indices[0], fileData + offset, m_Indices.size() * sizeof(unsigned int));
offset += m_Indices.size() * sizeof(unsigned int);
#else
#endif
}
+2 -2
View File
@@ -95,10 +95,10 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
model = ResourceManager::Load<::Model, true>(resource);
} catch (const Resource::StillLoadingException&) {
//continue;
model = ResourceManager::Load<::Model>("Models/Core/UnitRaptor.obj");
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
} catch (const std::exception&) {
try {
model = ResourceManager::Load<::Model>("Models/Core/Error.obj");
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
} catch (const std::exception&) {
continue;
}
+2 -2
View File
@@ -10,9 +10,9 @@ void Renderer::Initialize()
InitializeShaders();
InitializeTextures();
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
/* m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");*/
m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker);
+21 -9
View File
@@ -51,13 +51,15 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
GetMeshData(node);
}
}
MGlobal::displayInfo(MString() + "nrofmeshes: " + meshes.size());
WriteMeshData(pathName);
return true;
}
bool Export::Materials()
bool Export::Materials(std::string pathName)
{
if (!GetMaterialData())
return false;
WriteMaterialData(pathName);
return true;
}
@@ -73,17 +75,14 @@ bool Export::Animations(std::string pathName, std::vector<AnimationInfo> animInf
MGlobal::displayError(MString() + "Export::Animations() got no pathName. Do not know where to write file");
return false;
}
MGlobal::displayInfo("HALLOOOO");
allBindPoses = m_SkeletonHandler.GetBindPoses();
for (auto clip : animInfo) {
MGlobal::displayInfo("preben");
if (!GetAnimationData(clip)) {
MGlobal::displayError(MString() + "Export::Animations() failed to export " + clip.Name.c_str());
return false;
}
}
MGlobal::displayInfo("ghihgihi");
WriteAnimData(pathName);
return true;
}
@@ -100,11 +99,8 @@ bool Export::GetMeshData(MObject object)
bool Export::GetMaterialData()
{
// Traverse scene and return vector with all materials
std::vector<MaterialNode>* AllMaterials = m_MaterialHandler.DoIt();
AllMaterials = m_MaterialHandler.DoIt();
// Access the colorR component of one material (example)
cout << AllMaterials->at(0).Color[0] << endl;
MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]);
return true;
}
@@ -163,6 +159,22 @@ void Export::WriteAnimData(std::string pathName)
MGlobal::displayInfo("Export::WriteAnimData() got called when allBindPoses contained no data, did not write nor created them");
}
void Export::WriteMaterialData(std::string pathName)
{
m_MtrlFile.ASCIIFilePath(pathName +"_mtrl.txt");
m_MtrlFile.binaryFilePath(pathName + ".mtrl");
m_MtrlFile.OpenFiles();
int size = (*AllMaterials).size();
m_MtrlFile.writeToFiles(&size);
for (auto aMaterial : *AllMaterials) {
m_MtrlFile.writeToFiles((OutputData*)&aMaterial);
}
m_MtrlFile.CloseFiles();
}
Export::~Export()
{
/* delete m_MaterialHandler;
+5 -1
View File
@@ -23,7 +23,7 @@ public:
};
bool Meshes(std::string pathName, bool selectedOnly = false);
bool Materials();
bool Materials(std::string pathName);
bool Animations(std::string pathName, std::vector<AnimationInfo> animInfo);
private:
@@ -33,6 +33,7 @@ private:
void WriteMeshData(std::string pathName);
void WriteAnimData(std::string pathName);
void WriteMaterialData(std::string pathName);
Material m_MaterialHandler;
Skeleton m_SkeletonHandler;
@@ -42,6 +43,7 @@ private:
//File export
WriteToFile m_MeshFile;
WriteToFile m_AnimFile;
WriteToFile m_MtrlFile;
//Mesh Data
std::vector<Mesh> meshes;
@@ -50,5 +52,7 @@ private:
std::vector<BindPoseSkeletonNode> allBindPoses;
std::vector<Animation> allAnimations;
//Material Data
std::vector<MaterialNode>* AllMaterials;
};
#endif
+24 -61
View File
@@ -4,57 +4,24 @@ void Material::grabLambertProperties(MaterialNode& material_node, MFnDependencyN
{
material_node.Name = node.name().asChar();
if (findColorTexture(material_node, node)) {
material_node.Color.fill(1.0f);
}
else {
m_Plug = node.findPlug("colorR");
m_Plug.getValue(material_node.Color[0]);
m_Plug = node.findPlug("colorG");
m_Plug.getValue(material_node.Color[1]);
m_Plug = node.findPlug("colorB");
m_Plug.getValue(material_node.Color[2]);
if (!findColorTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no color texture. Please apply a texture insted of using a value");
}
float TempTransp[3];
m_Plug = node.findPlug("transparencyR");
m_Plug.getValue(TempTransp[0]);
m_Plug = node.findPlug("transparencyG");
m_Plug.getValue(TempTransp[1]);
m_Plug = node.findPlug("transparencyB");
m_Plug.getValue(TempTransp[2]);
MColor TranspNode(TempTransp[0], TempTransp[1], TempTransp[2]);
float DummyH, DummyS;
TranspNode.get(MColor::kHSV, DummyH, DummyS, material_node.Color[3]);
}
if (findIncandescenceTexture(material_node, node)) {
material_node.Incandescence.fill(1.0f);
}
else {
m_Plug = node.findPlug("incandescenceR");
m_Plug.getValue(material_node.Incandescence[0]);
m_Plug = node.findPlug("incandescenceG");
m_Plug.getValue(material_node.Incandescence[1]);
m_Plug = node.findPlug("incandescenceB");
m_Plug.getValue(material_node.Incandescence[2]);
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no Incandescence texture. Please apply a texture insted of using value");
}
findNormalTexture(material_node, node);
if (findNormalTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture. Please apply a texture to it");
}
}
void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node)
{
if (findSpecularTexture(material_node, node)) {
material_node.Specular.fill(1.0f);
}
else {
m_Plug = node.findPlug("specularColorR");
m_Plug.getValue(material_node.Specular[0]);
m_Plug = node.findPlug("specularColorG");
m_Plug.getValue(material_node.Specular[1]);
m_Plug = node.findPlug("specularColorB");
m_Plug.getValue(material_node.Specular[2]);
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it");
}
m_Plug = node.findPlug("reflectivity");
@@ -76,17 +43,9 @@ void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNod
void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node)
{
if (findSpecularTexture(material_node, node)) {
material_node.Specular.fill(1.0f);
}
else {
m_Plug = node.findPlug("specularColorR");
m_Plug.getValue(material_node.Specular[0]);
m_Plug = node.findPlug("specularColorG");
m_Plug.getValue(material_node.Specular[1]);
m_Plug = node.findPlug("specularColorB");
m_Plug.getValue(material_node.Specular[2]);
}
if (findSpecularTexture(material_node, node)) {
MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it");
}
m_Plug = node.findPlug("reflectivity");
m_Plug.getValue(material_node.ReflectionFactor);
@@ -109,8 +68,10 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode&
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
material_node.ColorMapFile = FullPath.substr(FullPath.find_last_of("/"));
FullPath = FullPath.substr(FullPath.find_last_of("/") + 1);
material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1;
// Test
MGlobal::displayInfo(MString() + "Texture file: " + FullPath.c_str());
return true;
@@ -140,8 +101,9 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode&
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
material_node.NormalMapFile = FullPath.substr(FullPath.find_last_of("/"));
FullPath = FullPath.substr(FullPath.find_last_of("/") + 1);
material_node.NormalMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
material_node.NormalMapFileLength = material_node.NormalMapFile.length() + 1;
return true;
}
}
@@ -165,8 +127,9 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/"));
FullPath = FullPath.substr(FullPath.find_last_of("/") + 1);
material_node.SpecularMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
material_node.SpecularMapFileLength = material_node.SpecularMapFile.length() + 1;
return true;
}
}
@@ -187,8 +150,9 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
m_TexturePaths.push_back(FullPath);
material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/"));
FullPath = FullPath.substr(FullPath.find_last_of("/") + 1);
material_node.IncandescenceMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
material_node.IncandescenceMapFileLength = material_node.IncandescenceMapFile.length() + 1;
return true;
}
}
@@ -206,7 +170,7 @@ std::vector<MaterialNode>* Material::DoIt()
{
// All materials we care about inherit from Lambert
MItDependencyNodes matIt(MFn::kLambert);
m_AllMaterials.clear();
while (!matIt.isDone()) {
MFnDependencyNode MaterialFnDN(matIt.thisNode());
MaterialNode MaterialStorage;
@@ -226,7 +190,6 @@ std::vector<MaterialNode>* Material::DoIt()
else if (matIt.thisNode().hasFn(MFn::kLambert)) {
grabLambertProperties(MaterialStorage, MaterialFnDN);
MaterialStorage.Specular.fill(0.0f);
MaterialStorage.ReflectionFactor = 0.0f;
MaterialStorage.SpecularExponent = 0.0f;
+64 -5
View File
@@ -5,21 +5,80 @@
#include <array>
#include <algorithm>
#include <cmath>
#include <map>
#include "MayaIncludes.h"
#include "OutputData.h"
#include "Mesh.h"
struct MaterialNode
class MaterialNode : public OutputData
{
public:
std::string Name;
std::array<float, 4> Color;
std::array<float, 3> Incandescence;
std::array<float, 3> Specular;
float ReflectionFactor;
float SpecularExponent;
float SpecularExponent;
unsigned int ColorMapFileLength = 0;
std::string ColorMapFile;
unsigned int SpecularMapFileLength = 0;
std::string SpecularMapFile;
unsigned int NormalMapFileLength = 0;
std::string NormalMapFile;
unsigned int IncandescenceMapFileLength = 0;
std::string IncandescenceMapFile;
unsigned int IndexStart;
unsigned int IndexEnd;
virtual void WriteBinary(std::ostream& out)
{
out.write((char*)&ColorMapFileLength, sizeof(unsigned int));
out.write((char*)&NormalMapFileLength, sizeof(unsigned int));
out.write((char*)&SpecularMapFileLength, sizeof(unsigned int));
out.write((char*)&IncandescenceMapFileLength, sizeof(unsigned int));
out.write((char*)&SpecularExponent, sizeof(float));
out.write((char*)&ReflectionFactor, sizeof(float));
out.write((char*)&IndexStart, sizeof(unsigned int));
out.write((char*)&IndexEnd, sizeof(unsigned int));
out.write(ColorMapFile.c_str(), ColorMapFileLength);
out.write(NormalMapFile.c_str(), NormalMapFileLength);
out.write(SpecularMapFile.c_str(), SpecularMapFileLength);
out.write(IncandescenceMapFile.c_str(), IncandescenceMapFileLength);
}
virtual void WriteASCII(std::ostream& out) const
{
out << "New Material _ not in binary" << endl;
out << "number of indices: " << Name << " _ not in binary" << endl;
out << "ColorMapFile length: " << ColorMapFileLength << endl;
out << "NormalMapFile length: " << NormalMapFileLength << endl;
out << "SpecularMapFile length: " << SpecularMapFileLength << endl;
out << "IncandescenceMapFile length: " << IncandescenceMapFileLength << endl;
out << "SpecularExponent: " << SpecularExponent << endl;
out << "ReflectionFactor: " << ReflectionFactor << endl;
out << "IndexStart: " << IndexStart << endl;
out << "IndexEnd: " << IndexEnd << endl;
out << "ColorMapFile length: " << ColorMapFileLength << endl;
if (ColorMapFileLength > 0)
out << "ColorMapFile: " << ColorMapFile << endl;
if (NormalMapFileLength > 0)
out << "NormalMapFile: " << NormalMapFile << endl;
if (SpecularMapFileLength > 0)
out << "SpecularMapFile: " << SpecularMapFile << endl;
if (IncandescenceMapFileLength > 0)
out << "IncandescenceMapFile: " << IncandescenceMapFile << endl;
}
};
class Material
+12 -13
View File
@@ -24,16 +24,15 @@ Menu::Menu(QDialog* dialog)
m_ExportSelectedButton = new QCheckBox(tr("&Export Selected"));
m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations"));
m_CopyTexturesButton = new QCheckBox(tr("&Copy Textures"));
m_Button3 = new QCheckBox(tr("Test Materials"));
m_ExportMaterialButton = new QCheckBox(tr("&Export Material"));;
m_ExportAnimationsButton->setChecked(true);
m_CopyTexturesButton->setChecked(true);
m_ExportMaterialButton->setChecked(true);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(m_ExportSelectedButton);
vbox->addWidget(m_ExportAnimationsButton);
vbox->addWidget(m_CopyTexturesButton);
vbox->addWidget(m_Button3);
vbox->addWidget(m_ExportMaterialButton);
vbox->addStretch(1);
optionsBox->setLayout(vbox);
@@ -46,8 +45,7 @@ Menu::Menu(QDialog* dialog)
connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_CopyTexturesButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_Button3, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_ExportMaterialButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
// Creating several layouts, adding widgets & adding them to one layout in the end
QHBoxLayout* topLayout = new QHBoxLayout;
@@ -178,20 +176,14 @@ void Menu::ExportAll(bool)
}
std::vector<Export::AnimationInfo> animations;
MGlobal::displayInfo(MString() + "yeeehaa");
for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) {
Export::AnimationInfo thisClip;
MGlobal::displayInfo(MString() + "qwqw");
thisClip.Name = std::string(m_AnimationClipName[i]->text().toLocal8Bit().constData());
MGlobal::displayInfo(MString() + "shizzzz");
thisClip.Start = m_StartFrameLines[i]->text().toInt();
MGlobal::displayInfo(MString() + "dsdsfg");
thisClip.End = m_EndFrameLines[i]->text().toInt();
MGlobal::displayInfo(MString() + "aaaaaaaaaaaaaaaaaaaa");
animations.push_back(thisClip);
}
MGlobal::displayInfo(MString() + "asdf");
if (m_ExportAnimationsButton->isChecked()) {
//Export Animations
if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) {
@@ -199,6 +191,13 @@ void Menu::ExportAll(bool)
return;
}
}
if (m_ExportMaterialButton->isChecked()) {
if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())){
MGlobal::displayError(MString() + "Could not export materials");
return;
}
}
}
void Menu::CancelClicked(bool)
+1 -2
View File
@@ -65,8 +65,7 @@ private:
QCheckBox* m_ExportSelectedButton = nullptr;
QCheckBox* m_ExportAnimationsButton = nullptr;
QCheckBox* m_CopyTexturesButton = nullptr;
QCheckBox* m_Button3 = nullptr;
QCheckBox* m_ExportMaterialButton = nullptr;
QLineEdit* m_ExportPath = nullptr;
QFileDialog* m_FileDialog = nullptr;
+140 -66
View File
@@ -76,8 +76,8 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
Mesh MeshClass::GetMeshData(MObject object)
{
Mesh newMesh;
std::vector<VertexLayout>& vertexList = newMesh.Vertices;
std::vector<int>& indexList = newMesh.Indices;
vector<VertexLayout>& vertexList = newMesh.Vertices;
map<string, vector<int>>& indexLists = newMesh.Indices;
// In here, we retrieve triangulated polygons from the mesh
MFnMesh mesh(object);
@@ -91,11 +91,28 @@ Mesh MeshClass::GetMeshData(MObject object)
float2 UV;
double biTangent[3];
double biNormal[3];
VertexLayout thisVertex;
MFloatVectorArray Tangents;
MFloatVectorArray biNormals;
std::map<int, WeightInfo> vertexWeights = GetWeightData();
MObjectArray shaderList;
MIntArray shaderIndexList;
mesh.getConnectedShaders(0, shaderList, shaderIndexList);
map<string, vector<int>> materialFaceIDs;
MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length());
MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length());
MPlugArray plugArray;
for (int i = 0; i < shaderIndexList.length(); i++)
{
MFnDependencyNode shader(shaderList[shaderIndexList[i]]);
MPlug p_Plug = shader.findPlug("surfaceShader");
if (p_Plug.connectedTo(plugArray, true, false)) {
MFnDependencyNode node = plugArray[0].node();
materialFaceIDs[node.name().asChar()].push_back(i);
}
}
map<int, WeightInfo> vertexWeights = GetWeightData();
mesh.getTangents(Tangents, MSpace::kObject, NULL);
mesh.getBinormals(biNormals, MSpace::kObject, NULL);
@@ -103,82 +120,139 @@ Mesh MeshClass::GetMeshData(MObject object)
MItMeshFaceVertex faceVert(object);
int intDummy = 0;
MItMeshPolygon meshPolyIter(object);
for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) {
for (auto aMaterial : materialFaceIDs) {
for (auto faceID : aMaterial.second) {
vector<unsigned int> localVertexToGlobalIndex;
unsigned int indexOffset = vertexList.size();
vector<array<unsigned int, 2>> localVertexToGlobalIndex;
meshPolyIter.setIndex(faceID, intDummy);
meshPolyIter.getVertices(vertices);
meshPolyIter.getTriangles(dummy, triangleList);
meshPolyIter.getVertices(vertices);
meshPolyIter.getTriangles(dummy, triangleList);
//MGlobal::displayInfo("Befor Second Loop");
for (unsigned int i = 0; i < vertices.length(); i++) {
VertexLayout thisVertex;
vertexIndex = meshPolyIter.vertexIndex(i);
faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy);
//MGlobal::displayInfo("In Second Loop");
pos = faceVert.position();
if (abs(pos.x) > 0.0001)
thisVertex.Pos[0] = pos.x;
if (abs(pos.y) > 0.0001)
thisVertex.Pos[1] = pos.y;
if (abs(pos.z) > 0.0001)
thisVertex.Pos[2] = pos.z;
//MGlobal::displayInfo("Befor Second Loop");
for (unsigned int i = 0; i < vertices.length(); i++) {
vertexIndex = meshPolyIter.vertexIndex(i);
faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy);
//MGlobal::displayInfo("In Second Loop");
faceVert.position().get(thisVertex.Pos);
faceVert.getNormal(normal);
thisVertex.Normal[0] = normal[0];
thisVertex.Normal[1] = normal[1];
thisVertex.Normal[2] = normal[2];
faceVert.getNormal(normal);
if (abs(normal[0]) > 0.0001)
thisVertex.Normal[0] = normal[0];
if (abs(normal[1]) > 0.0001)
thisVertex.Normal[1] = normal[1];
if (abs(normal[2]) > 0.0001)
thisVertex.Normal[2] = normal[2];
MFloatVector Tangent = Tangents[faceVert.tangentId()];
//MVector tmp = faceVert.getTangent(MSpace::kObject, NULL);
//tmp.get(biTangent);
thisVertex.Tangent[0] = Tangent[0];
thisVertex.Tangent[1] = Tangent[1];
thisVertex.Tangent[2] = Tangent[2];
MFloatVector Tangent = Tangents[faceVert.tangentId()];
//MVector tmp = faceVert.getTangent(MSpace::kObject, NULL);
//tmp.get(biTangent);
if (abs(Tangent[0]) > 0.0001)
thisVertex.Tangent[0] = Tangent[0];
if (abs(Tangent[1]) > 0.0001)
thisVertex.Tangent[1] = Tangent[1];
if (abs(Tangent[2]) > 0.0001)
thisVertex.Tangent[2] = Tangent[2];
MFloatVector biNormal = biNormals[faceVert.tangentId()];
//faceVert.getBinormal().get(biNormal);
thisVertex.BiNormal[0] = biNormal[0];
thisVertex.BiNormal[1] = biNormal[1];
thisVertex.BiNormal[2] = biNormal[2];
MFloatVector biNormal = biNormals[faceVert.tangentId()];
//faceVert.getBinormal().get(biNormal);
if (abs(biNormal[0]) > 0.0001)
thisVertex.BiNormal[0] = biNormal[0];
if (abs(biNormal[1]) > 0.0001)
thisVertex.BiNormal[1] = biNormal[1];
if (abs(biNormal[2]) > 0.0001)
thisVertex.BiNormal[2] = biNormal[2];
faceVert.getUV(UV);
thisVertex.Uv[0] = UV[0];
thisVertex.Uv[1] = UV[1];
faceVert.getUV(UV);
thisVertex.Uv[0] = UV[0];
thisVertex.Uv[1] = UV[1];
thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0];
thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1];
thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2];
thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3];
thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0];
thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1];
thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2];
thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3];
thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0];
thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1];
thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2];
thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3];
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001)
thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0];
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001)
thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1];
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001)
thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2];
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001)
thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3];
std::vector<VertexLayout>::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex);
if (it != vertexList.end()) {
localVertexToGlobalIndex.push_back(vertexIndex);
} else {
localVertexToGlobalIndex.push_back(vertexIndex);
vertexList.push_back(thisVertex);
}
//cout << "Pos: " << thisVertex.Pos[0] << "/" << thisVertex.Pos[1] << "/" << thisVertex.Pos[2] << endl;
//cout << "Normals: " << thisVertex.Normal[0] << "/" << thisVertex.Normal[1] << "/" << thisVertex.Normal[2] << endl;
//cout << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl;
//cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl;
//cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl;
}
for (unsigned int i = 0; i < triangleList.length(); i++) {
unsigned int k = 0;
if (localVertexToGlobalIndex.size() > 0) {
while (localVertexToGlobalIndex[k] != triangleList[i] && k < localVertexToGlobalIndex.size()) {
k++;
float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
if (totalWeight < 1.00f && totalWeight > 0.01f) {
thisVertex.BoneWeights[0] /= totalWeight;
thisVertex.BoneWeights[1] /= totalWeight;
thisVertex.BoneWeights[2] /= totalWeight;
thisVertex.BoneWeights[3] /= totalWeight;
}
indexList.push_back(indexOffset + k);
}
std::vector<VertexLayout>::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex);
array<unsigned int, 2> tmp;
if (it != vertexList.end()) {
tmp[0] = vertexIndex;
tmp[1] = it - vertexList.begin();
localVertexToGlobalIndex.push_back(tmp);
} else {
tmp[0] = vertexIndex;
tmp[1] = vertexList.size();
localVertexToGlobalIndex.push_back(tmp);
vertexList.push_back(thisVertex);
}
//MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1]: " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][0] + " " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][1]);
//cout << "Pos: " << thisVertex.Pos[0] << "/" << thisVertex.Pos[1] << "/" << thisVertex.Pos[2] << endl;
//cout << "Normals: " << thisVertex.Normal[0] << "/" << thisVertex.Normal[1] << "/" << thisVertex.Normal[2] << endl;
//cout << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl;
//cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl;
//cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl;
}
for (unsigned int i = 0; i < triangleList.length(); i++) {
unsigned int k = 0;
if (localVertexToGlobalIndex.size() > 0) {
//MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]);
while (localVertexToGlobalIndex[k][0] != triangleList[i] && k < localVertexToGlobalIndex.size()) {
k++;
}
//MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k][0] + " " + localVertexToGlobalIndex[k][1]);
indexLists[aMaterial.first.c_str()].push_back(localVertexToGlobalIndex[k][1]);
}
}
}
// MGlobal::displayInfo( MString() + "localVertexToGlobalIndex.size(): " + localVertexToGlobalIndex.size());
// if (localVertexToGlobalIndex.size() > 0) {
// MGlobal::displayInfo(MString() + "triangleList.length(): " + triangleList.length());
// for (unsigned int i = triangleList.length() - 1; i >= 0; i--) {
// MGlobal::displayInfo(MString() + "i: " + i);
// unsigned int k = localVertexToGlobalIndex.size() - 1;
// MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]);
// while (localVertexToGlobalIndex[k] != triangleList[i] && k >= 0) {
// MGlobal::displayInfo(MString() + "k: " + k);
// k--;
// }
// MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k]);
// indexList.push_back(indexOffset + k);
// }
// }
}
newMesh.NumIndices = newMesh.Indices.size();
int totalIndecies = 0;
for (auto aList : newMesh.Indices) {
totalIndecies += aList.second.size();
}
newMesh.NumIndices = totalIndecies;
newMesh.NumVertices = newMesh.Vertices.size();
return newMesh;
+22 -17
View File
@@ -3,6 +3,7 @@
#include <map>
#include <vector>
#include <array>
#include "OutputData.h"
#include "MayaIncludes.h"
@@ -10,20 +11,20 @@
class VertexLayout : public OutputData
{
public:
float Pos[3];
float Normal[3];
float Tangent[3];
float BiNormal[3];
float Uv[2];
float BoneIndices[4];
float BoneWeights[4];
float Pos[3]{ 0 };
float Normal[3]{ 0 };
float Tangent[3]{ 0 };
float BiNormal[3]{ 0 };
float Uv[2]{ 0 };
float BoneIndices[4]{ 0 };
float BoneWeights[4]{ 0 };
virtual void WriteBinary(std::ostream& out)
{
out.write((char*)&Pos, sizeof(float) * 3);
out.write((char*)&Normal, sizeof(float) * 3);
out.write((char*)&Tangent, sizeof(float) * 3);
out.write((char*)&BiTangent, sizeof(float) * 3);
out.write((char*)&BiNormal, sizeof(float) * 3);
out.write((char*)&Uv, sizeof(float) * 2);
out.write((char*)&BoneIndices, sizeof(float) * 4);
out.write((char*)&BoneWeights, sizeof(float) * 4);
@@ -34,7 +35,7 @@ public:
out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl;
out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl;
out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl;
out << BiTangent[0] << " " << BiTangent[1] << " " << BiTangent[2] << endl;
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl;
out << Uv[0] << " " << Uv[1] << endl;
out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl;
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl;
@@ -46,7 +47,7 @@ public:
this->Pos[0] == right.Pos[0] && this->Pos[1] == right.Pos[1] && this->Pos[2] == right.Pos[2] &&
this->Normal[0] == right.Normal[0] && this->Normal[1] == right.Normal[1] && this->Normal[2] == right.Normal[2] &&
this->Tangent[0] == right.Tangent[0] && this->Tangent[1] == right.Tangent[1] && this->Tangent[2] == right.Tangent[2] &&
this->BiTangent[0] == right.BiTangent[0] && this->BiTangent[1] == right.BiTangent[1] && this->BiTangent[2] == right.BiTangent[2] &&
this->BiNormal[0] == right.BiNormal[0] && this->BiNormal[1] == right.BiNormal[1] && this->BiNormal[2] == right.BiNormal[2] &&
this->Uv[0] == right.Uv[0] && this->Uv[1] == right.Uv[1] &&
this->BoneIndices[0] == right.BoneIndices[0] && this->BoneIndices[1] == right.BoneIndices[1] && this->BoneIndices[2] == right.BoneIndices[2] && this->BoneIndices[3] == right.BoneIndices[3] &&
this->BoneWeights[0] == right.BoneWeights[0] && this->BoneWeights[1] == right.BoneWeights[1] && this->BoneWeights[2] == right.BoneWeights[2] && this->BoneWeights[3] == right.BoneWeights[3]
@@ -56,10 +57,10 @@ public:
class Mesh : public OutputData {
public:
int NumVertices;
int NumIndices;
unsigned int NumVertices;
unsigned int NumIndices;
std::vector<VertexLayout> Vertices;
std::vector<int> Indices;
std::map<std::string, std::vector<int>> Indices;
virtual void WriteBinary(std::ostream& out)
{
@@ -69,7 +70,7 @@ public:
aVertex.WriteBinary(out);
}
for (auto aIndex : Indices) {
out.write((char*)&aIndex, sizeof(int));
out.write((char*)aIndex.second.data(), sizeof(int) * aIndex.second.size());
}
}
@@ -80,12 +81,16 @@ public:
out << "number of indices: " << NumIndices << endl;
int vertexNumber = 0;
for (auto aVertex : Vertices) {
out << "New vertex number: " << vertexNumber << "_ not in binary" << endl;
out << "New vertex number: " << vertexNumber << " _ not in binary" << endl;
aVertex.WriteASCII(out);
vertexNumber++;
}
for (int i = 0; i < NumIndices; i += 3) {
out << Indices[i] << " " << Indices[i+1] << " " << Indices[i + 2] << endl;
out << "New vertex Triangels: " << NumIndices/3 << " _ not in binary" << endl;
for (auto aIndexList : Indices) {
out << "Using Material: " << aIndexList.first << " _ not in binary" << endl;
for (int i = 0; i < aIndexList.second.size(); i += 3) {
out << aIndexList.second[i] << " " << aIndexList.second[i+1] << " " << aIndexList.second[i + 2] << endl;
}
}
}
};