diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 7d3794765..5b9710e02 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -65,6 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace Assimp; @@ -117,8 +118,8 @@ PbrtExporter::PbrtExporter ( // Write scene-wide rendering options WriteSceneWide(); - // Write geometry - WriteGeometry(); + // Write the Shapes + WriteShapes(); // Write World Description WriteWorldDefinition(); @@ -354,7 +355,7 @@ void PbrtExporter::WriteCamera(int i) { << "[" << fov << "]" << std::endl; } -void PbrtExporter::WriteGeometry() { +void PbrtExporter::WriteShapes() { // - figure out if should all be in 1 file (no camera?) // - if more than 1 file, place each geo in separate directory // - NEED to figure out how meshes are/should be split up @@ -363,7 +364,6 @@ void PbrtExporter::WriteGeometry() { // bool mIOSystem->CreateDirectory(path) // TODO worry about sequestering geo later, after giant print - // TODO rewrite as WriteShapes & WriteShape } void PbrtExporter::WriteWorldDefinition() { @@ -375,8 +375,8 @@ void PbrtExporter::WriteWorldDefinition() { // Print WorldBegin mOutput << "WorldBegin" << std::endl; - // Print Textures - WriteTextures(); + // Check to see if the scene has Embedded Textures + WriteEmbeddedTextures(); // Print materials WriteMaterials(); @@ -398,21 +398,18 @@ void PbrtExporter::WriteWorldDefinition() { } -void PbrtExporter::WriteTextures() { +void PbrtExporter::WriteEmbeddedTextures() { mOutput << std::endl; mOutput << "###################" << std::endl; - mOutput << "# Writing Textures:" << std::endl; + mOutput << "# Checking Embededded Textures:" << 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; if (mScene->mNumTextures == 0) return; - for (int i = 0 ; i < mScene->mNumTextures; i++) { - // TODO - } - + mOutput << "# ERROR: PBRT does not support Embedded Textures" << std::endl; } 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 + // 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 + mOutput << "MakeNamedMaterial \"" << materialName.C_Str() << "\"" + << " \"string type\" \"uber\"" << std::endl; + } @@ -453,6 +475,7 @@ void PbrtExporter::WriteLights() { mOutput << mScene->mNumLights << std::endl; // TODO remove default ambient term when numCameras == 0 + // For now, ambient may only be necessary for debug mOutput << "# - Creating a default blueish ambient light source" << 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; } - // Check for Alpha texture + // TODO Check for Alpha texture mOutput << "# - Alpha texture: " << std::endl; - // TODO // Create ObjectBegin mOutput << "ObjectBegin \""; @@ -600,8 +622,6 @@ void PbrtExporter::WriteObjectInstances() { } void PbrtExporter::WriteObjectInstance(aiNode* node, aiMatrix4x4 parent) { - // TODO IMMEDIATELY fix transforms for nodes - auto w2o = parent * node->mTransformation; // 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_EXPORT diff --git a/code/Pbrt/PbrtExporter.h b/code/Pbrt/PbrtExporter.h index 6621f78ca..b91b02b37 100644 --- a/code/Pbrt/PbrtExporter.h +++ b/code/Pbrt/PbrtExporter.h @@ -54,13 +54,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include // shared_ptr #include // stringstream struct aiScene; struct aiNode; -//struct aiMaterial; +struct aiMaterial; namespace Assimp { @@ -98,6 +99,10 @@ private: /// Name of the file (without extension) where the scene will be exported const std::string mFile; +private: + // A private set to keep track of which textures have been declared + std::set mTextureSet; + private: // Writing the comment header void WriteHeader(); @@ -108,8 +113,8 @@ private: // Writing the pbrt scene-wide rendering options void WriteSceneWide(); - // Writing the geometry to distinct files - void WriteGeometry(); + // Writing the shapes to distinct files + void WriteShapes(); // Writing the pbrt world defintion void WriteWorldDefinition(); @@ -118,12 +123,13 @@ private: void WriteCameras(); void WriteCamera(int i); - // Writing the Texture data - void WriteTextures(); + // Writing the Embedded Texture data + void WriteEmbeddedTextures(); // Writing the Material data void WriteMaterials(); void WriteMaterial(int i); + void WriteNewTextures(aiMaterial* material); // Writing the Light data void WriteLights();