Printing out unique textures
parent
3dc550a9b2
commit
2c9d3bea64
|
@ -65,6 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
|
@ -117,8 +118,8 @@ PbrtExporter::PbrtExporter (
|
||||||
// Write scene-wide rendering options
|
// Write scene-wide rendering options
|
||||||
WriteSceneWide();
|
WriteSceneWide();
|
||||||
|
|
||||||
// Write geometry
|
// Write the Shapes
|
||||||
WriteGeometry();
|
WriteShapes();
|
||||||
|
|
||||||
// Write World Description
|
// Write World Description
|
||||||
WriteWorldDefinition();
|
WriteWorldDefinition();
|
||||||
|
@ -354,7 +355,7 @@ void PbrtExporter::WriteCamera(int i) {
|
||||||
<< "[" << fov << "]" << std::endl;
|
<< "[" << fov << "]" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PbrtExporter::WriteGeometry() {
|
void PbrtExporter::WriteShapes() {
|
||||||
// - figure out if should all be in 1 file (no camera?)
|
// - figure out if should all be in 1 file (no camera?)
|
||||||
// - if more than 1 file, place each geo in separate directory
|
// - if more than 1 file, place each geo in separate directory
|
||||||
// - NEED to figure out how meshes are/should be split up
|
// - NEED to figure out how meshes are/should be split up
|
||||||
|
@ -363,7 +364,6 @@ void PbrtExporter::WriteGeometry() {
|
||||||
// bool mIOSystem->CreateDirectory(path)
|
// bool mIOSystem->CreateDirectory(path)
|
||||||
|
|
||||||
// TODO worry about sequestering geo later, after giant print
|
// TODO worry about sequestering geo later, after giant print
|
||||||
// TODO rewrite as WriteShapes & WriteShape
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PbrtExporter::WriteWorldDefinition() {
|
void PbrtExporter::WriteWorldDefinition() {
|
||||||
|
@ -375,8 +375,8 @@ void PbrtExporter::WriteWorldDefinition() {
|
||||||
// Print WorldBegin
|
// Print WorldBegin
|
||||||
mOutput << "WorldBegin" << std::endl;
|
mOutput << "WorldBegin" << std::endl;
|
||||||
|
|
||||||
// Print Textures
|
// Check to see if the scene has Embedded Textures
|
||||||
WriteTextures();
|
WriteEmbeddedTextures();
|
||||||
|
|
||||||
// Print materials
|
// Print materials
|
||||||
WriteMaterials();
|
WriteMaterials();
|
||||||
|
@ -398,21 +398,18 @@ void PbrtExporter::WriteWorldDefinition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PbrtExporter::WriteTextures() {
|
void PbrtExporter::WriteEmbeddedTextures() {
|
||||||
mOutput << std::endl;
|
mOutput << std::endl;
|
||||||
mOutput << "###################" << std::endl;
|
mOutput << "###################" << std::endl;
|
||||||
mOutput << "# Writing Textures:" << std::endl;
|
mOutput << "# Checking Embededded Textures:" << std::endl;
|
||||||
mOutput << "###################" << std::endl;
|
mOutput << "###################" << std::endl;
|
||||||
mOutput << "# - Number of Textures found in scene: ";
|
mOutput << "# - Number of Embedded Textures found in scene: ";
|
||||||
mOutput << mScene->mNumTextures << std::endl;
|
mOutput << mScene->mNumTextures << std::endl;
|
||||||
|
|
||||||
if (mScene->mNumTextures == 0)
|
if (mScene->mNumTextures == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0 ; i < mScene->mNumTextures; i++) {
|
mOutput << "# ERROR: PBRT does not support Embedded Textures" << std::endl;
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PbrtExporter::WriteMaterials() {
|
void PbrtExporter::WriteMaterials() {
|
||||||
|
@ -437,10 +434,35 @@ void PbrtExporter::WriteMaterials() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PbrtExporter::WriteMaterial(int i) {
|
void PbrtExporter::WriteMaterial(int m) {
|
||||||
|
auto material = mScene->mMaterials[m];
|
||||||
|
|
||||||
|
// get material name
|
||||||
|
auto materialName = material->GetName();
|
||||||
|
mOutput << std::endl << "# - Material " << m+1 << ": "
|
||||||
|
<< materialName.C_Str() << std::endl;
|
||||||
|
|
||||||
|
// Print out number of properties
|
||||||
|
mOutput << "# - Number of Material Properties: "
|
||||||
|
<< material->mNumProperties << std::endl;
|
||||||
|
|
||||||
|
// print out texture properties parsing through by type
|
||||||
|
// then print out any new textures
|
||||||
|
WriteNewTextures(material);
|
||||||
|
|
||||||
// TODO IMMEDIATELY
|
// TODO IMMEDIATELY
|
||||||
|
// Determine if this material should be one of:
|
||||||
|
// - disney (has BASE_COLOR?)
|
||||||
|
// - matte (has only kd?)
|
||||||
|
// - metal (never? has only ks?)
|
||||||
|
// - mirror (has reflection)
|
||||||
|
// - plastic (never?)
|
||||||
|
// - uber (general?)
|
||||||
|
|
||||||
// Use MakeNamedMaterial to give variable names to materials
|
// Use MakeNamedMaterial to give variable names to materials
|
||||||
|
mOutput << "MakeNamedMaterial \"" << materialName.C_Str() << "\""
|
||||||
|
<< " \"string type\" \"uber\"" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -453,6 +475,7 @@ void PbrtExporter::WriteLights() {
|
||||||
mOutput << mScene->mNumLights << std::endl;
|
mOutput << mScene->mNumLights << std::endl;
|
||||||
|
|
||||||
// TODO remove default ambient term when numCameras == 0
|
// TODO remove default ambient term when numCameras == 0
|
||||||
|
|
||||||
// For now, ambient may only be necessary for debug
|
// For now, ambient may only be necessary for debug
|
||||||
mOutput << "# - Creating a default blueish ambient light source" << std::endl;
|
mOutput << "# - Creating a default blueish ambient light source" << std::endl;
|
||||||
mOutput << "LightSource \"infinite\" \"rgb L\" [0.4 0.45 0.5]" << std::endl;
|
mOutput << "LightSource \"infinite\" \"rgb L\" [0.4 0.45 0.5]" << std::endl;
|
||||||
|
@ -528,9 +551,8 @@ void PbrtExporter::WriteObject(int i) {
|
||||||
mOutput << "# - Defaulting to first Texture Coordinate specified" << std::endl;
|
mOutput << "# - Defaulting to first Texture Coordinate specified" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for Alpha texture
|
// TODO Check for Alpha texture
|
||||||
mOutput << "# - Alpha texture: " << std::endl;
|
mOutput << "# - Alpha texture: " << std::endl;
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Create ObjectBegin
|
// Create ObjectBegin
|
||||||
mOutput << "ObjectBegin \"";
|
mOutput << "ObjectBegin \"";
|
||||||
|
@ -600,8 +622,6 @@ void PbrtExporter::WriteObjectInstances() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PbrtExporter::WriteObjectInstance(aiNode* node, aiMatrix4x4 parent) {
|
void PbrtExporter::WriteObjectInstance(aiNode* node, aiMatrix4x4 parent) {
|
||||||
// TODO IMMEDIATELY fix transforms for nodes
|
|
||||||
|
|
||||||
auto w2o = parent * node->mTransformation;
|
auto w2o = parent * node->mTransformation;
|
||||||
|
|
||||||
// Print transformation for this node
|
// Print transformation for this node
|
||||||
|
@ -631,5 +651,141 @@ void PbrtExporter::WriteObjectInstance(aiNode* node, aiMatrix4x4 parent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PbrtExporter::WriteNewTextures(aiMaterial* material) {
|
||||||
|
// Print out texture type counts
|
||||||
|
int textureCounts[aiTextureType_UNKNOWN];
|
||||||
|
for (int i = 1; i <= aiTextureType_UNKNOWN; i++) {
|
||||||
|
textureCounts[i-1] = material->GetTextureCount(aiTextureType(i));
|
||||||
|
}
|
||||||
|
mOutput << "# - Texture Type Counts:" << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_DIFFUSE: " << textureCounts[0] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_SPECULAR: " << textureCounts[1] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_AMBIENT: " << textureCounts[2] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_EMISSIVE: " << textureCounts[3] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_HEIGHT: " << textureCounts[4] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_NORMALS: " << textureCounts[5] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_SHININESS: " << textureCounts[6] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_OPACITY: " << textureCounts[7] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_DISPLACEMENT: " << textureCounts[8] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_LIGHTMAP: " << textureCounts[9] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_REFLECTION: " << textureCounts[10] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_BASE_COLOR: " << textureCounts[11] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_NORMAL_CAMERA: " << textureCounts[12] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_EMISSION_COLOR: " << textureCounts[13] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_METALNESS: " << textureCounts[14] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_DIFFUSE_ROUGHNESS: " << textureCounts[15] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_AMBIENT_OCCLUSION: " << textureCounts[16] << std::endl;
|
||||||
|
mOutput << "# - aiTextureType_UNKNOWN: " << textureCounts[17] << std::endl;
|
||||||
|
|
||||||
|
for (int tt = 1; tt <= aiTextureType_UNKNOWN; tt++) {
|
||||||
|
C_STRUCT aiString path;
|
||||||
|
//aiTextureMapping mapping;
|
||||||
|
//unsigned int uvindex;
|
||||||
|
//ai_real blend;
|
||||||
|
//aiTextureOp op;
|
||||||
|
aiTextureMapMode mapmode;
|
||||||
|
|
||||||
|
for (int t = 0; t < textureCounts[tt-1]; t++) {
|
||||||
|
material->GetTexture(
|
||||||
|
aiTextureType(tt),
|
||||||
|
t,
|
||||||
|
&path,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&mapmode);
|
||||||
|
|
||||||
|
std::stringstream name;
|
||||||
|
std::string spath = std::string(path.C_Str());
|
||||||
|
std::replace(spath.begin(), spath.end(), '\\', '/');
|
||||||
|
name << spath << "_";
|
||||||
|
switch(aiTextureType(tt)) {
|
||||||
|
case aiTextureType_DIFFUSE :
|
||||||
|
name << "diffuse";
|
||||||
|
break;
|
||||||
|
case aiTextureType_SPECULAR :
|
||||||
|
name << "specular";
|
||||||
|
break;
|
||||||
|
case aiTextureType_AMBIENT :
|
||||||
|
name << "ambient";
|
||||||
|
break;
|
||||||
|
case aiTextureType_EMISSIVE :
|
||||||
|
name << "emissive";
|
||||||
|
break;
|
||||||
|
case aiTextureType_HEIGHT :
|
||||||
|
name << "height";
|
||||||
|
break;
|
||||||
|
case aiTextureType_NORMALS :
|
||||||
|
name << "normals";
|
||||||
|
break;
|
||||||
|
case aiTextureType_SHININESS :
|
||||||
|
name << "shininess";
|
||||||
|
break;
|
||||||
|
case aiTextureType_OPACITY :
|
||||||
|
name << "opacity";
|
||||||
|
break;
|
||||||
|
case aiTextureType_DISPLACEMENT :
|
||||||
|
name << "displacement";
|
||||||
|
break;
|
||||||
|
case aiTextureType_LIGHTMAP :
|
||||||
|
name << "lightmap";
|
||||||
|
break;
|
||||||
|
case aiTextureType_REFLECTION :
|
||||||
|
name << "reflection";
|
||||||
|
break;
|
||||||
|
case aiTextureType_BASE_COLOR :
|
||||||
|
name << "base_color";
|
||||||
|
break;
|
||||||
|
case aiTextureType_NORMAL_CAMERA :
|
||||||
|
name << "normal_camera";
|
||||||
|
break;
|
||||||
|
case aiTextureType_EMISSION_COLOR :
|
||||||
|
name << "emission_color";
|
||||||
|
break;
|
||||||
|
case aiTextureType_METALNESS :
|
||||||
|
name << "metalness";
|
||||||
|
break;
|
||||||
|
case aiTextureType_DIFFUSE_ROUGHNESS :
|
||||||
|
name << "diffuse_roughness";
|
||||||
|
break;
|
||||||
|
case aiTextureType_AMBIENT_OCCLUSION :
|
||||||
|
name << "ambient_occlusion";
|
||||||
|
break;
|
||||||
|
case aiTextureType_UNKNOWN :
|
||||||
|
name << "unknown";
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mTextureSet.find(name.str()) == mTextureSet.end()) {
|
||||||
|
mOutput << "Texture \"" << name.str() << "\" \"spectrum\" "
|
||||||
|
<< "\"string filename\" \"" << spath << "\" "
|
||||||
|
<< "\"string wrap\" \"";
|
||||||
|
switch (mapmode) {
|
||||||
|
case aiTextureMapMode_Wrap :
|
||||||
|
mOutput << "repeat\"" << std::endl;
|
||||||
|
break;
|
||||||
|
case aiTextureMapMode_Clamp :
|
||||||
|
mOutput << "clamp\"" << std::endl;
|
||||||
|
break;
|
||||||
|
case aiTextureMapMode_Decal :
|
||||||
|
mOutput << "black\"" << std::endl;
|
||||||
|
break;
|
||||||
|
case aiTextureMapMode_Mirror :
|
||||||
|
// PBRT doesn't support mirroring textures
|
||||||
|
mOutput << "repeat\"" << std::endl;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mOutput << "ERROR\"" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // ASSIMP_BUILD_NO_PBRT_EXPORTER
|
#endif // ASSIMP_BUILD_NO_PBRT_EXPORTER
|
||||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||||
|
|
|
@ -54,13 +54,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <memory> // shared_ptr
|
#include <memory> // shared_ptr
|
||||||
#include <sstream> // stringstream
|
#include <sstream> // stringstream
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
//struct aiMaterial;
|
struct aiMaterial;
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
{
|
{
|
||||||
|
@ -98,6 +99,10 @@ private:
|
||||||
/// Name of the file (without extension) where the scene will be exported
|
/// Name of the file (without extension) where the scene will be exported
|
||||||
const std::string mFile;
|
const std::string mFile;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// A private set to keep track of which textures have been declared
|
||||||
|
std::set<std::string> mTextureSet;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Writing the comment header
|
// Writing the comment header
|
||||||
void WriteHeader();
|
void WriteHeader();
|
||||||
|
@ -108,8 +113,8 @@ private:
|
||||||
// Writing the pbrt scene-wide rendering options
|
// Writing the pbrt scene-wide rendering options
|
||||||
void WriteSceneWide();
|
void WriteSceneWide();
|
||||||
|
|
||||||
// Writing the geometry to distinct files
|
// Writing the shapes to distinct files
|
||||||
void WriteGeometry();
|
void WriteShapes();
|
||||||
|
|
||||||
// Writing the pbrt world defintion
|
// Writing the pbrt world defintion
|
||||||
void WriteWorldDefinition();
|
void WriteWorldDefinition();
|
||||||
|
@ -118,12 +123,13 @@ private:
|
||||||
void WriteCameras();
|
void WriteCameras();
|
||||||
void WriteCamera(int i);
|
void WriteCamera(int i);
|
||||||
|
|
||||||
// Writing the Texture data
|
// Writing the Embedded Texture data
|
||||||
void WriteTextures();
|
void WriteEmbeddedTextures();
|
||||||
|
|
||||||
// Writing the Material data
|
// Writing the Material data
|
||||||
void WriteMaterials();
|
void WriteMaterials();
|
||||||
void WriteMaterial(int i);
|
void WriteMaterial(int i);
|
||||||
|
void WriteNewTextures(aiMaterial* material);
|
||||||
|
|
||||||
// Writing the Light data
|
// Writing the Light data
|
||||||
void WriteLights();
|
void WriteLights();
|
||||||
|
|
Loading…
Reference in New Issue