@@ -324,13 +324,13 @@ void SrcScene::processMeshes(aiNode* anode, std::shared_ptr<SrcNode> aSrcNode) {
324324 for (unsigned int i = 0 ; i < anode->mNumMeshes ; i++) {
325325 unsigned int meshIndex = anode->mMeshes [i];
326326 if ( meshIndex >= mSrcMeshes .size () ) {
327- ofLogError (" SrcScene ::processNodesRecursive" ) << " mesh index out of range: " << meshIndex << " / " << mSrcMeshes .size () << " num in scene: " << scene->mNumMeshes ;
327+ ofLogError (" ofxAssimp::Scene ::processNodesRecursive" ) << " mesh index out of range: " << meshIndex << " / " << mSrcMeshes .size () << " num in scene: " << scene->mNumMeshes ;
328328 continue ;
329329 }
330330 if ( mSrcMeshes [meshIndex] ) {
331- ofLogWarning (" SrcScene::processNodesRecursive" ) << " hmm we already have a SrcMesh at index: " << meshIndex << " " << anode->mName .data ;
331+ ofLogWarning (" ofxAssimp:: SrcScene::processNodesRecursive" ) << " hmm we already have a SrcMesh at index: " << meshIndex << " " << anode->mName .data ;
332332 } else {
333- ofLogNotice ( " SrcScene::processNodesRecursive" ) << " going to process mesh: " << scene->mMeshes [meshIndex]->mName .data << " from node: " << anode->mName .data << " num scene meshes: " << scene->mNumMeshes ;
333+ ofLogVerbose ( " ofxAssimp:: SrcScene::processNodesRecursive" ) << " going to process mesh: " << scene->mMeshes [meshIndex]->mName .data << " from node: " << anode->mName .data << " num scene meshes: " << scene->mNumMeshes ;
334334 // ok, open slot for a src mesh //
335335 auto srcMesh = std::make_shared<ofxAssimp::SrcMesh>();
336336 srcMesh->setAiMesh (scene->mMeshes [meshIndex], anode );
@@ -497,7 +497,7 @@ void SrcScene::processKeyframes(std::shared_ptr<ofxAssimp::SrcNode> aSrcNode, ai
497497 keyCollection.clear ();
498498 keyCollection.setup ( aNodeAnim, anim.getDurationInTicks () );
499499
500- // ofLogNotice("SrcScene processKeyframes: ") << aSrcNode->getName() << " node anim: " << aNodeAnim->mNodeName.data << " node anim num pos keyframes: " << aNodeAnim->mNumPositionKeys << " scale: " << aNodeAnim->mNumScalingKeys << " rot: " << aNodeAnim->mNumRotationKeys;
500+ // ofLogNotice("ofxAssimp:: SrcScene processKeyframes: ") << aSrcNode->getName() << " node anim: " << aNodeAnim->mNodeName.data << " node anim num pos keyframes: " << aNodeAnim->mNumPositionKeys << " scale: " << aNodeAnim->mNumScalingKeys << " rot: " << aNodeAnim->mNumRotationKeys;
501501
502502 double startTime = 0.0 ; // seconds
503503 double endTime = anim.getDurationInTicks ();// seconds;
@@ -570,6 +570,7 @@ void SrcScene::loadGLResources(std::shared_ptr<ofxAssimp::SrcMesh> aSrcMesh, aiM
570570
571571 if (AI_SUCCESS == aiGetMaterialColor (mtl, AI_MATKEY_COLOR_EMISSIVE, &tcolor)){
572572 auto col = ofxAssimp::Utils::aiColorToOfColor (tcolor);
573+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " setting emissive color: " << col;
573574 aSrcMesh->material ->setEmissiveColor (col);
574575 }
575576
@@ -586,6 +587,35 @@ void SrcScene::loadGLResources(std::shared_ptr<ofxAssimp::SrcMesh> aSrcMesh, aiM
586587 aSrcMesh->blendMode =OF_BLENDMODE_ADD;
587588 }
588589 }
590+
591+ float metallic = 0 .f ;
592+ if ( AI_SUCCESS == aiGetMaterialFloat (mtl, AI_MATKEY_METALLIC_FACTOR, &metallic) ) {
593+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " setting metallic value: " << metallic;
594+ aSrcMesh->material ->setMetallic (metallic);
595+ }
596+
597+ float roughness = 0 .f ;
598+ if ( AI_SUCCESS == aiGetMaterialFloat (mtl, AI_MATKEY_ROUGHNESS_FACTOR, &roughness) ) {
599+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " setting roughness value: " << roughness;
600+ aSrcMesh->material ->setRoughness (roughness);
601+ }
602+
603+ float clearcoatFactor = 0 .f ;
604+ if ( AI_SUCCESS == aiGetMaterialFloat (mtl, AI_MATKEY_CLEARCOAT_FACTOR, &clearcoatFactor) ) {
605+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " setting clearcoat value: " << clearcoatFactor;
606+ aSrcMesh->material ->setClearCoatStrength (clearcoatFactor);
607+ if ( clearcoatFactor > 0 .0f ) {
608+ aSrcMesh->material ->setClearCoatEnabled (true );
609+ } else {
610+ aSrcMesh->material ->setClearCoatEnabled (false );
611+ }
612+ }
613+
614+ float clearcoatRoughFactor = 0 .f ;
615+ if ( AI_SUCCESS == aiGetMaterialFloat (mtl, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR, &clearcoatRoughFactor) ) {
616+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " setting clearcoat roughness value: " << clearcoatRoughFactor;
617+ aSrcMesh->material ->setClearCoatRoughness (clearcoatRoughFactor);
618+ }
589619 }
590620
591621 // Culling
@@ -615,11 +645,19 @@ void SrcScene::loadGLResources(std::shared_ptr<ofxAssimp::SrcMesh> aSrcMesh, aiM
615645 for (int d = 0 ; d <= AI_TEXTURE_TYPE_MAX; d++){
616646 if (AI_SUCCESS == mtl->GetTexture ((aiTextureType)d, texIndex, &texPath, NULL , NULL , NULL , NULL , &texMapMode[0 ])){
617647
648+ // getTextureTypeAsString(const ofMaterialTextureType & aMaterialTextureType)
649+ auto matType = ofxAssimp::Texture::ofTextureTypeForAiType ( (aiTextureType)d );
650+ auto texTypeString = ofMaterial::getTextureTypeAsString (matType);
618651 // this is a solution to support older versions of assimp. see the weak defination above
619652 if ( aiTextureTypeToString ){
620653 ofLogVerbose (" ofxAssimp::SrcScene" ) << " loadGLResource(): loading " << aiTextureTypeToString ((aiTextureType)d) << " image from \" " << texPath.data << " \" " ;
621654 }
622655
656+ if ( matType == OF_MATERIAL_TEXTURE_NONE ) {
657+ ofLogWarning (" ofxAssimp::SrcScene" ) << " unable to detect texture type: " << texPath.data ;
658+ continue ;
659+ }
660+
623661 bool bWrap = (texMapMode[0 ]==aiTextureMapMode_Wrap);
624662
625663 std::string texPathStr = texPath.C_Str ();
@@ -657,26 +695,22 @@ void SrcScene::loadGLResources(std::shared_ptr<ofxAssimp::SrcMesh> aSrcMesh, aiM
657695 }
658696#endif
659697
698+
699+
660700 bool bTextureAlreadyExists = false ;
661- if (mAssimpTextures .count (realPath)){
701+ // if(mAssimpTextures.count(realPath)){
702+ if (mTextureCacheMap .count (realPath)) {
662703 bTextureAlreadyExists = true ;
663704 }
664705
665706 if (bTextureAlreadyExists) {
666- // ofxAssimpTexture assimpTexture;
667- // assimpTexture.setup(*textures[realPath].get(), realPath, bWrap);
668- // assimpTexture.setTextureType((aiTextureType)d);
669- auto assimpTexture = mAssimpTextures [realPath];
670- aSrcMesh->addTexture (assimpTexture);
671-
672707 ofLogVerbose (" ofxAssimp::SrcScene" ) << " loadGLResource(): texture already loaded: \" "
673- << mFile .getFileName () + " \" from \" " << realPath.string () << " \" " << " adding texture as " << assimpTexture-> getAiTextureTypeAsString () ;
708+ << mFile .getFileName () + " \" from \" " << realPath.string () << " \" " << " adding texture as " << texTypeString ;
674709 } else {
675- // shared_ptr<ofTexture> texture = std::make_shared<ofTexture>();
676- auto assimpTexture = std::make_shared<ofxAssimp::Texture>();
710+ shared_ptr<ofTexture> texture = std::make_shared<ofTexture>();
711+ // auto assimpTexture = std::make_shared<ofxAssimp::Texture>();
677712
678713 if ( bHasEmbeddedTexture ){
679-
680714#ifndef TARGET_LINUX_ARM
681715 auto embeddedTexture = scene->GetEmbeddedTexture (ogPath.c_str ());
682716
@@ -691,34 +725,49 @@ void SrcScene::loadGLResources(std::shared_ptr<ofxAssimp::SrcMesh> aSrcMesh, aiM
691725
692726 ofLogVerbose (" ofxAssimp::SrcScene" ) << " loadGLResource() texture size is " << tmp.getWidth () << " x" << tmp.getHeight ();
693727
694- assimpTexture->getTextureRef ().loadData (tmp.getPixels ());
728+ // assimpTexture->getTextureRef().loadData(tmp.getPixels());
729+ texture->loadData (tmp.getPixels ());
695730 }else {
696731 // uncompressed texture - might need swizzling from argb to rgba?
697732 auto glFormat = getGLFormatFromAiFormat (embeddedTexture->achFormatHint );
698- assimpTexture->getTextureRef ().loadData ((const uint8_t *)embeddedTexture->pcData , embeddedTexture->mWidth , embeddedTexture->mHeight , glFormat);
733+ // assimpTexture->getTextureRef().loadData((const uint8_t *)embeddedTexture->pcData, embeddedTexture->mWidth, embeddedTexture->mHeight, glFormat);
734+ texture->loadData ((const uint8_t *)embeddedTexture->pcData , embeddedTexture->mWidth , embeddedTexture->mHeight , glFormat);
699735 }
700736#endif
701737 }else {
702- // ofLoadImage(*texture.get (), realPath);
703- ofLoadImage (assimpTexture-> getTextureRef () , realPath );
738+ // ofLoadImage(assimpTexture->getTextureRef (), realPath );
739+ ofLoadImage (*texture , realPath);
704740 }
705741
706- if (assimpTexture && assimpTexture->getTextureRef ().isAllocated ()){
707- // ofxAssimpTexture tmpTex;
708- // tmpTex.setup(*texture.get(), realPath, bWrap);
709- assimpTexture->setup ( realPath, bWrap );
710- assimpTexture->setAiTextureType ((aiTextureType)d);
711- mAssimpTextures [realPath] = assimpTexture;
712- ofLogNotice ( " ofxAssimp::SrcScene" ) << " assimpTexture type: " << assimpTexture->getAiTextureTypeAsString () << " path: " << assimpTexture->getTexturePath ();
713- // tmpTex.setTextureType((aiTextureType)d);
714- aSrcMesh->addTexture ( assimpTexture );
715-
716- ofLogVerbose (" ofxAssimp::SrcScene" ) << " loadGLResource(): texture " << assimpTexture->getAiTextureTypeAsString () << " loaded, dimensions: " << assimpTexture->getTextureRef ().getWidth () << " x" << assimpTexture->getTextureRef ().getHeight ();
742+ if (texture && texture->isAllocated ()){
743+ mTextureCacheMap [realPath] = texture;
744+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " loadGLResource(): texture " << texTypeString << " loaded, dimensions: " << texture->getWidth () << " x" << texture->getHeight ();
717745 }else {
718746 ofLogError (" ofxAssimp::SrcScene" ) << " loadGLResource(): couldn't load texture: \" "
719747 << mFile .getFileName () + " \" from \" " << realPath.string () << " \" " ;
720748 }
721749 }
750+
751+
752+ if (mTextureCacheMap .count (realPath) > 0 ) {
753+ // create a key using the type of texture and the path
754+ std::string assimpTexKey = texTypeString+" _" +realPath.string ();
755+ std::shared_ptr<ofxAssimp::Texture> assimpTexture;
756+ if ( mAssimpTextures .count (assimpTexKey) ) {
757+ assimpTexture = mAssimpTextures [assimpTexKey];
758+ } else {
759+ assimpTexture = std::make_shared<ofxAssimp::Texture>();
760+ assimpTexture->setup ( realPath, bWrap );
761+ assimpTexture->setAiTextureType ((aiTextureType)d);
762+ assimpTexture->setTexture (mTextureCacheMap [realPath]);
763+ mAssimpTextures [assimpTexKey] = assimpTexture;
764+ }
765+
766+ if ( assimpTexture ) {
767+ ofLogVerbose (" ofxAssimp::SrcScene" ) << " adding texture type: " << texTypeString << " to mesh: " << aSrcMesh->getName ();
768+ aSrcMesh->addTexture ( assimpTexture );
769+ }
770+ }
722771 }
723772 }
724773 }
0 commit comments