Now supporting multiple material per mesh. Simon changed glDrawElementsBaseVertex to glDrawElements in DrawFinalPass.cpp Hallelulijah!
This commit is contained in:
@@ -19,9 +19,10 @@ public:
|
|||||||
|
|
||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
GLuint ElementBuffer;
|
GLuint ElementBuffer;
|
||||||
|
RawModel* m_RawModel;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RawModel* m_RawModel;
|
|
||||||
GLuint VertexBuffer;
|
GLuint VertexBuffer;
|
||||||
GLuint NormalBuffer;
|
GLuint NormalBuffer;
|
||||||
GLuint TangentNormalsBuffer;
|
GLuint TangentNormalsBuffer;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class RawModel : public Resource
|
|||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RawModel(std::string fileName);
|
RawModel(std::string& fileName);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~RawModel();
|
~RawModel();
|
||||||
@@ -63,12 +63,18 @@ public:
|
|||||||
glm::mat4 m_Matrix;
|
glm::mat4 m_Matrix;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
void ReadMeshFile(std::string filePath);
|
||||||
void ReadMeshFileHeader(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 ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||||
void ReadVertices(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 ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||||
|
|
||||||
|
void ReadMaterialFile(std::string filePath);
|
||||||
|
void ReadMaterials(unsigned int &offset, char* fileData, unsigned int& fileByteSize);
|
||||||
|
void ReadMaterialSingle(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);
|
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>models/coolTriangle.mesh</Resource>
|
<Resource>models/Baljj</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
</Components>
|
</Components>
|
||||||
|
|||||||
@@ -291,21 +291,21 @@ void EditorSystem::createWidget()
|
|||||||
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneX, "Model");
|
m_World->AttachComponent(m_WidgetPlaneX, "Model");
|
||||||
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh";
|
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube";
|
||||||
m_WidgetY = m_World->CreateEntity(m_Widget);
|
m_WidgetY = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetY, "Transform");
|
m_World->AttachComponent(m_WidgetY, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetY, "Model");
|
m_World->AttachComponent(m_WidgetY, "Model");
|
||||||
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneY, "Model");
|
m_World->AttachComponent(m_WidgetPlaneY, "Model");
|
||||||
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh";
|
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube";
|
||||||
m_WidgetZ = m_World->CreateEntity(m_Widget);
|
m_WidgetZ = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetZ, "Transform");
|
m_World->AttachComponent(m_WidgetZ, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetZ, "Model");
|
m_World->AttachComponent(m_WidgetZ, "Model");
|
||||||
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
|
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
|
||||||
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh";
|
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube";
|
||||||
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
|
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetOrigin, "Transform");
|
m_World->AttachComponent(m_WidgetOrigin, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetOrigin, "Model");
|
m_World->AttachComponent(m_WidgetOrigin, "Model");
|
||||||
|
|||||||
@@ -56,9 +56,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
|||||||
|
|
||||||
glBindVertexArray(modelJob->Model->VAO);
|
glBindVertexArray(modelJob->Model->VAO);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GLERROR("DrawFinalPass::Draw: END");
|
GLERROR("DrawFinalPass::Draw: END");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ DrawFinalPassState::DrawFinalPassState()
|
|||||||
Enable(GL_BLEND);
|
Enable(GL_BLEND);
|
||||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
Enable(GL_DEPTH_TEST);
|
Enable(GL_DEPTH_TEST);
|
||||||
Enable(GL_CULL_FACE);
|
Disable(GL_CULL_FACE); //Should be enabled, fix it johan and andreas.
|
||||||
ClearColor(glm::vec4(200.f / 255, 0.f / 255, 200.f / 255, 0.f));
|
ClearColor(glm::vec4(200.f / 255, 0.f / 255, 200.f / 255, 0.f));
|
||||||
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
#include "Rendering\RawModelCustom.h"
|
#include "Rendering/RawModelCustom.h"
|
||||||
|
|
||||||
RawModel::RawModel(std::string fileName)
|
RawModel::RawModel(std::string& fileName)
|
||||||
{
|
{
|
||||||
|
ReadMeshFile(fileName);
|
||||||
|
ReadMaterialFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RawModel::ReadMeshFile(std::string filePath)
|
||||||
|
{
|
||||||
char* fileData;
|
char* fileData;
|
||||||
std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate);
|
filePath += ".mesh";
|
||||||
|
std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate);
|
||||||
|
|
||||||
if (!in.is_open()) {
|
if (!in.is_open()) {
|
||||||
throw Resource::FailedLoadingException("Open file failed");
|
throw Resource::FailedLoadingException("Open mesh file failed");
|
||||||
}
|
}
|
||||||
unsigned int fileByteSize = in.tellg();
|
unsigned int fileByteSize = in.tellg();
|
||||||
in.seekg(0, std::ios_base::beg);
|
in.seekg(0, std::ios_base::beg);
|
||||||
@@ -21,23 +28,13 @@ RawModel::RawModel(std::string fileName)
|
|||||||
ReadMesh(offset, fileData, fileByteSize);
|
ReadMesh(offset, fileData, fileByteSize);
|
||||||
}
|
}
|
||||||
delete fileData;
|
delete fileData;
|
||||||
MaterialGroup mat;
|
|
||||||
mat.StartIndex = 0;
|
|
||||||
mat.EndIndex = m_Indices.size() - 1;
|
|
||||||
MaterialGroups.push_back(mat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
unsigned int test;
|
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
||||||
test = *(unsigned int*)fileData;
|
|
||||||
unsigned int* test2;
|
|
||||||
test2 = (unsigned int*)fileData;
|
|
||||||
|
|
||||||
m_Vertices.resize(test);
|
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
test = *(unsigned int*)(fileData + offset);
|
|
||||||
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
#else
|
#else
|
||||||
@@ -78,6 +75,115 @@ void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& f
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RawModel::ReadMaterialFile(std::string filePath)
|
||||||
|
{
|
||||||
|
char* fileData;
|
||||||
|
filePath += ".mtrl";
|
||||||
|
std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate);
|
||||||
|
|
||||||
|
if (!in.is_open()) {
|
||||||
|
throw Resource::FailedLoadingException("Open material file failed");
|
||||||
|
}
|
||||||
|
unsigned int fileByteSize = in.tellg();
|
||||||
|
in.seekg(0, std::ios_base::beg);
|
||||||
|
|
||||||
|
fileData = new char[fileByteSize];
|
||||||
|
in.read(fileData, fileByteSize);
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
unsigned int offset = 0;
|
||||||
|
if (fileByteSize > 0) {
|
||||||
|
ReadMaterials(offset, fileData, fileByteSize);
|
||||||
|
}
|
||||||
|
delete fileData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
|
{
|
||||||
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
|
unsigned int* numMaterials = (unsigned int*)(fileData);
|
||||||
|
MaterialGroups.reserve(*numMaterials);
|
||||||
|
offset += sizeof(unsigned int);
|
||||||
|
|
||||||
|
for (int i = 0; i < *numMaterials; i++) {
|
||||||
|
ReadMaterialSingle(offset, fileData, fileByteSize);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||||
|
{
|
||||||
|
MaterialGroup newMaterial;
|
||||||
|
|
||||||
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
|
|
||||||
|
if (offset + sizeof(unsigned int) * 4 > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading Material texture names length failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.SpecularExponent = *(float*)(fileData + offset);
|
||||||
|
offset += sizeof(float);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.StartIndex = *(unsigned int*)(fileData + offset);
|
||||||
|
offset += sizeof(unsigned int);
|
||||||
|
newMaterial.EndIndex = *(unsigned int*)(fileData + offset);
|
||||||
|
offset += sizeof(unsigned int);
|
||||||
|
|
||||||
|
if (nameLengths[0] > 0) {
|
||||||
|
if (offset + nameLengths[0] > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading Material texture path failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.TexturePath = (fileData + offset);
|
||||||
|
offset += nameLengths[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameLengths[1] > 0) {
|
||||||
|
if (offset + nameLengths[1] > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading Material NormalMap path failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.NormalMapPath = (fileData + offset);
|
||||||
|
offset += nameLengths[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameLengths[2] > 0) {
|
||||||
|
if (offset + nameLengths[2] > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading Material SpecularMap path failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.SpecularMapPath = (fileData + offset);
|
||||||
|
offset += nameLengths[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameLengths[3] > 0) {
|
||||||
|
if (offset + nameLengths[3] > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading Material IncandescenceMap path failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
newMaterial.IncandescenceMapPath = (fileData + offset);
|
||||||
|
offset += nameLengths[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MaterialGroups.push_back(newMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
RawModel::~RawModel()
|
RawModel::~RawModel()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -95,10 +95,10 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
|
|||||||
model = ResourceManager::Load<::Model, true>(resource);
|
model = ResourceManager::Load<::Model, true>(resource);
|
||||||
} catch (const Resource::StillLoadingException&) {
|
} catch (const Resource::StillLoadingException&) {
|
||||||
//continue;
|
//continue;
|
||||||
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
|
model = ResourceManager::Load<::Model>("Models/coolCube");
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
try {
|
try {
|
||||||
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
|
model = ResourceManager::Load<::Model>("Models/coolCube");
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
|
|
||||||
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
|
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
|
||||||
FillDepth(*scene);
|
FillDepth(*scene);
|
||||||
m_PickingPass->Draw(*scene);
|
//m_PickingPass->Draw(*scene);
|
||||||
m_LightCullingPass->GenerateNewFrustum(*scene);
|
//m_LightCullingPass->GenerateNewFrustum(*scene);
|
||||||
m_LightCullingPass->FillLightList(*scene);
|
//m_LightCullingPass->FillLightList(*scene);
|
||||||
m_LightCullingPass->CullLights(*scene);
|
//m_LightCullingPass->CullLights(*scene);
|
||||||
m_DrawFinalPass->Draw(*scene);
|
m_DrawFinalPass->Draw(*scene);
|
||||||
//m_DrawScenePass->Draw(rq);
|
//m_DrawScenePass->Draw(rq);
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
|||||||
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
|
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
meshes.clear();
|
|
||||||
|
|
||||||
|
MObjectArray Objects;
|
||||||
if (selectedOnly) {
|
if (selectedOnly) {
|
||||||
// Retrieving the objects we currently have selected
|
// Retrieving the objects we currently have selected
|
||||||
MSelectionList selected;
|
MSelectionList selected;
|
||||||
@@ -25,7 +25,7 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
|||||||
|
|
||||||
if (object.hasFn(MFn::kMesh)) {
|
if (object.hasFn(MFn::kMesh)) {
|
||||||
MFnDependencyNode thisNode(object);
|
MFnDependencyNode thisNode(object);
|
||||||
GetMeshData(object);
|
Objects.append(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -48,9 +48,10 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
|||||||
if (next)
|
if (next)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
GetMeshData(node);
|
Objects.append(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GetMeshData(Objects);
|
||||||
WriteMeshData(pathName);
|
WriteMeshData(pathName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -87,19 +88,16 @@ bool Export::Animations(std::string pathName, std::vector<AnimationInfo> animInf
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Export::GetMeshData(MObject object)
|
bool Export::GetMeshData(MObjectArray object)
|
||||||
{
|
{
|
||||||
if (!object.hasFn(MFn::kMesh))
|
meshes = m_MeshHandler.GetMeshData(object);
|
||||||
return false;
|
|
||||||
|
|
||||||
meshes.push_back(m_MeshHandler.GetMeshData(object));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Export::GetMaterialData()
|
bool Export::GetMaterialData()
|
||||||
{
|
{
|
||||||
// Traverse scene and return vector with all materials
|
// Traverse scene and return vector with all materials
|
||||||
AllMaterials = m_MaterialHandler.DoIt();
|
AllMaterials = m_MaterialHandler.DoIt(meshes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -126,9 +124,7 @@ void Export::WriteMeshData(std::string pathName)
|
|||||||
|
|
||||||
m_MeshFile.OpenFiles();
|
m_MeshFile.OpenFiles();
|
||||||
|
|
||||||
for (auto aMesh : meshes) {
|
m_MeshFile.writeToFiles((OutputData*)&meshes);
|
||||||
m_MeshFile.writeToFiles((OutputData*)&aMesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_MeshFile.CloseFiles();
|
m_MeshFile.CloseFiles();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
bool Animations(std::string pathName, std::vector<AnimationInfo> animInfo);
|
bool Animations(std::string pathName, std::vector<AnimationInfo> animInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetMeshData(MObject object);
|
bool GetMeshData(MObjectArray object);
|
||||||
bool GetMaterialData();
|
bool GetMaterialData();
|
||||||
bool GetAnimationData(AnimationInfo info);
|
bool GetAnimationData(AnimationInfo info);
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ private:
|
|||||||
WriteToFile m_MtrlFile;
|
WriteToFile m_MtrlFile;
|
||||||
|
|
||||||
//Mesh Data
|
//Mesh Data
|
||||||
std::vector<Mesh> meshes;
|
Mesh meshes;
|
||||||
|
|
||||||
//Animation Data
|
//Animation Data
|
||||||
std::vector<BindPoseSkeletonNode> allBindPoses;
|
std::vector<BindPoseSkeletonNode> allBindPoses;
|
||||||
|
|||||||
@@ -166,36 +166,42 @@ std::vector<std::string>* Material::TexturePaths()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Traverse the DAG and grab all the materials
|
// Traverse the DAG and grab all the materials
|
||||||
std::vector<MaterialNode>* Material::DoIt()
|
std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
|
||||||
{
|
{
|
||||||
// All materials we care about inherit from Lambert
|
// All materials we care about inherit from Lambert
|
||||||
MItDependencyNodes matIt(MFn::kLambert);
|
MItDependencyNodes matIt(MFn::kLambert);
|
||||||
m_AllMaterials.clear();
|
m_AllMaterials.clear();
|
||||||
|
int totalIndices = 0;
|
||||||
while (!matIt.isDone()) {
|
while (!matIt.isDone()) {
|
||||||
MFnDependencyNode MaterialFnDN(matIt.thisNode());
|
MFnDependencyNode MaterialFnDN(matIt.thisNode());
|
||||||
MaterialNode MaterialStorage;
|
MaterialNode MaterialStorage;
|
||||||
|
bool meshHasMaterial = false;
|
||||||
|
//Mesh Indices is a map with <string : MaterialName, vector<int> : indices>
|
||||||
|
for (auto aMeshMaterial : mesh.Indices) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (meshHasMaterial) {
|
||||||
|
grabLambertProperties(MaterialStorage, MaterialFnDN);
|
||||||
|
|
||||||
if (matIt.thisNode().hasFn(MFn::kPhong)) {
|
if (matIt.thisNode().hasFn(MFn::kPhong)) {
|
||||||
grabLambertProperties(MaterialStorage, MaterialFnDN);
|
grabPhongProperties(MaterialStorage, MaterialFnDN);
|
||||||
grabPhongProperties(MaterialStorage, MaterialFnDN);
|
|
||||||
|
|
||||||
m_AllMaterials.push_back(MaterialStorage);
|
} else if (matIt.thisNode().hasFn(MFn::kBlinn)) {
|
||||||
}
|
grabBlinnProperties(MaterialStorage, MaterialFnDN);
|
||||||
else if (matIt.thisNode().hasFn(MFn::kBlinn)) {
|
|
||||||
grabLambertProperties(MaterialStorage, MaterialFnDN);
|
|
||||||
grabBlinnProperties(MaterialStorage, MaterialFnDN);
|
|
||||||
|
|
||||||
m_AllMaterials.push_back(MaterialStorage);
|
} else if (matIt.thisNode().hasFn(MFn::kLambert)) {
|
||||||
}
|
MaterialStorage.ReflectionFactor = 0.0f;
|
||||||
else if (matIt.thisNode().hasFn(MFn::kLambert)) {
|
MaterialStorage.SpecularExponent = 0.0f;
|
||||||
grabLambertProperties(MaterialStorage, MaterialFnDN);
|
}
|
||||||
|
|
||||||
MaterialStorage.ReflectionFactor = 0.0f;
|
|
||||||
MaterialStorage.SpecularExponent = 0.0f;
|
|
||||||
|
|
||||||
m_AllMaterials.push_back(MaterialStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
m_AllMaterials.push_back(MaterialStorage);
|
||||||
|
}
|
||||||
matIt.next();
|
matIt.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ public:
|
|||||||
out << "IndexStart: " << IndexStart << endl;
|
out << "IndexStart: " << IndexStart << endl;
|
||||||
out << "IndexEnd: " << IndexEnd << endl;
|
out << "IndexEnd: " << IndexEnd << endl;
|
||||||
|
|
||||||
out << "ColorMapFile length: " << ColorMapFileLength << endl;
|
|
||||||
if (ColorMapFileLength > 0)
|
if (ColorMapFileLength > 0)
|
||||||
out << "ColorMapFile: " << ColorMapFile << endl;
|
out << "ColorMapFile: " << ColorMapFile << endl;
|
||||||
|
|
||||||
if (NormalMapFileLength > 0)
|
if (NormalMapFileLength > 0)
|
||||||
out << "NormalMapFile: " << NormalMapFile << endl;
|
out << "NormalMapFile: " << NormalMapFile << endl;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class Material
|
|||||||
public:
|
public:
|
||||||
Material() {};
|
Material() {};
|
||||||
~Material() {};
|
~Material() {};
|
||||||
std::vector<MaterialNode>* DoIt();
|
std::vector<MaterialNode>* DoIt(Mesh mesh);
|
||||||
std::vector<std::string>* TexturePaths();
|
std::vector<std::string>* TexturePaths();
|
||||||
private:
|
private:
|
||||||
MPlug m_Plug;
|
MPlug m_Plug;
|
||||||
|
|||||||
@@ -73,186 +73,201 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
|
|||||||
return weightMap;
|
return weightMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh MeshClass::GetMeshData(MObject object)
|
Mesh MeshClass::GetMeshData(MObjectArray object)
|
||||||
{
|
{
|
||||||
Mesh newMesh;
|
Mesh newMesh;
|
||||||
vector<VertexLayout>& vertexList = newMesh.Vertices;
|
vector<VertexLayout>& vertexList = newMesh.Vertices;
|
||||||
map<string, vector<int>>& indexLists = newMesh.Indices;
|
map<string, vector<int>>& indexLists = newMesh.Indices;
|
||||||
// In here, we retrieve triangulated polygons from the mesh
|
for (int ObjectID = 0; ObjectID < object.length(); ObjectID++) {
|
||||||
MFnMesh mesh(object);
|
if (!object[ObjectID].hasFn(MFn::kMesh))
|
||||||
|
continue;
|
||||||
|
|
||||||
map<unsigned int, vector<unsigned int>> vertexToIndex;;
|
// In here, we retrieve triangulated polygons from the mesh
|
||||||
|
MFnMesh mesh(object[ObjectID]);
|
||||||
|
MDagPathArray dagPaths;
|
||||||
|
MDagPath::getAllPathsTo(object[ObjectID], dagPaths);
|
||||||
|
for (int pathID = 0; pathID < dagPaths.length(); pathID++) {
|
||||||
|
MGlobal::displayInfo(dagPaths[pathID].fullPathName());
|
||||||
|
MDagPath thisMeshPath(dagPaths[pathID]);
|
||||||
|
MMatrix transformMatrix = thisMeshPath.inclusiveMatrix();
|
||||||
|
|
||||||
MIntArray intdexOffsetVertexCount, vertices, triangleList;
|
map<unsigned int, vector<unsigned int>> vertexToIndex;;
|
||||||
MPointArray dummy;
|
|
||||||
unsigned int vertexIndex;
|
|
||||||
MVector normal;
|
|
||||||
MPoint pos;
|
|
||||||
float2 UV;
|
|
||||||
double biTangent[3];
|
|
||||||
double biNormal[3];
|
|
||||||
MFloatVectorArray Tangents;
|
|
||||||
MFloatVectorArray biNormals;
|
|
||||||
|
|
||||||
MObjectArray shaderList;
|
MIntArray intdexOffsetVertexCount, vertices, triangleList;
|
||||||
MIntArray shaderIndexList;
|
MPointArray dummy;
|
||||||
mesh.getConnectedShaders(0, shaderList, shaderIndexList);
|
unsigned int vertexIndex;
|
||||||
|
MVector normal;
|
||||||
|
MPoint pos;
|
||||||
|
float2 UV;
|
||||||
|
double biTangent[3];
|
||||||
|
double biNormal[3];
|
||||||
|
MFloatVectorArray Tangents;
|
||||||
|
MFloatVectorArray biNormals;
|
||||||
|
|
||||||
map<string, vector<int>> materialFaceIDs;
|
MObjectArray shaderList;
|
||||||
MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length());
|
MIntArray shaderIndexList;
|
||||||
MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length());
|
mesh.getConnectedShaders(0, shaderList, shaderIndexList);
|
||||||
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);
|
map<string, vector<int>> materialFaceIDs;
|
||||||
mesh.getBinormals(biNormals, MSpace::kObject, NULL);
|
MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length());
|
||||||
|
MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length());
|
||||||
MItMeshFaceVertex faceVert(object);
|
MPlugArray plugArray;
|
||||||
|
for (int i = 0; i < shaderIndexList.length(); i++) {
|
||||||
int intDummy = 0;
|
MFnDependencyNode shader(shaderList[shaderIndexList[i]]);
|
||||||
|
MPlug p_Plug = shader.findPlug("surfaceShader");
|
||||||
MItMeshPolygon meshPolyIter(object);
|
if (p_Plug.connectedTo(plugArray, true, false)) {
|
||||||
|
MFnDependencyNode node = plugArray[0].node();
|
||||||
for (auto aMaterial : materialFaceIDs) {
|
materialFaceIDs[node.name().asChar()].push_back(i);
|
||||||
for (auto faceID : aMaterial.second) {
|
|
||||||
|
|
||||||
vector<array<unsigned int, 2>> localVertexToGlobalIndex;
|
|
||||||
meshPolyIter.setIndex(faceID, intDummy);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
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];
|
|
||||||
|
|
||||||
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];
|
|
||||||
|
|
||||||
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];
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
map<int, WeightInfo> vertexWeights = GetWeightData();
|
||||||
if (localVertexToGlobalIndex.size() > 0) {
|
|
||||||
//MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]);
|
mesh.getTangents(Tangents, MSpace::kTransform, NULL);
|
||||||
while (localVertexToGlobalIndex[k][0] != triangleList[i] && k < localVertexToGlobalIndex.size()) {
|
mesh.getBinormals(biNormals, MSpace::kTransform, NULL);
|
||||||
k++;
|
|
||||||
|
MItMeshFaceVertex faceVert(object[ObjectID]);
|
||||||
|
|
||||||
|
int intDummy = 0;
|
||||||
|
|
||||||
|
MItMeshPolygon meshPolyIter(object[ObjectID]);
|
||||||
|
MFloatPointArray positions;
|
||||||
|
|
||||||
|
mesh.getPoints(positions);
|
||||||
|
|
||||||
|
for (auto aMaterial : materialFaceIDs) {
|
||||||
|
for (auto faceID : aMaterial.second) {
|
||||||
|
|
||||||
|
vector<array<unsigned int, 2>> localVertexToGlobalIndex;
|
||||||
|
meshPolyIter.setIndex(faceID, intDummy);
|
||||||
|
|
||||||
|
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(MSpace::kTransform);
|
||||||
|
//mesh.getPoint(vertexIndex, pos, MSpace::kPostTransform);
|
||||||
|
pos = positions[vertexIndex];
|
||||||
|
pos = pos * transformMatrix;
|
||||||
|
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;
|
||||||
|
|
||||||
|
faceVert.getNormal(normal, MSpace::kTransform);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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];
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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[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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int totalIndices = 0;
|
||||||
int totalIndecies = 0;
|
|
||||||
for (auto aList : newMesh.Indices) {
|
for (auto aList : newMesh.Indices) {
|
||||||
totalIndecies += aList.second.size();
|
totalIndices += aList.second.size();
|
||||||
}
|
}
|
||||||
|
newMesh.NumIndices = totalIndices;
|
||||||
newMesh.NumIndices = totalIndecies;
|
|
||||||
newMesh.NumVertices = newMesh.Vertices.size();
|
newMesh.NumVertices = newMesh.Vertices.size();
|
||||||
|
|
||||||
return newMesh;
|
return newMesh;
|
||||||
|
|||||||
@@ -69,8 +69,9 @@ public:
|
|||||||
for (auto aVertex : Vertices) {
|
for (auto aVertex : Vertices) {
|
||||||
aVertex.WriteBinary(out);
|
aVertex.WriteBinary(out);
|
||||||
}
|
}
|
||||||
for (auto aIndex : Indices) {
|
//for (auto aIndex : Indices) {
|
||||||
out.write((char*)aIndex.second.data(), sizeof(int) * aIndex.second.size());
|
for (std::map<std::string, std::vector<int>>::reverse_iterator aIndex = Indices.rbegin(); aIndex != Indices.rend(); aIndex++){
|
||||||
|
out.write((char*)(*aIndex).second.data(), sizeof(int) * (*aIndex).second.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ class MeshClass
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MeshClass();
|
MeshClass();
|
||||||
Mesh GetMeshData(MObject Object);
|
Mesh GetMeshData(MObjectArray Object);
|
||||||
~MeshClass();
|
~MeshClass();
|
||||||
private:
|
private:
|
||||||
struct WeightInfo {
|
struct WeightInfo {
|
||||||
|
|||||||
Reference in New Issue
Block a user