Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcAnimKeyCollection.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
//
// ofxAssimpSrcAnimKeyCollection.cpp
// Created by Nick Hardeman on 11/1/23.
//

#include "ofxAssimpSrcAnimKeyCollection.h"
#include "ofxAssimpUtils.h"

using namespace ofx::assimp;
using namespace ofxAssimp;

//--------------------------------------------------------------
void SrcAnimKeyCollection::setup( aiNodeAnim* aNodeAnim, float aDurationInTicks ) {
Expand All @@ -21,7 +16,7 @@ bool SrcAnimKeyCollection::hasKeys() {


//--------------------------------------------------------------
glm::vec3 SrcAnimKeyCollection::getVec3ForTime( const float& atime, const std::vector<ofx::assimp::AnimVectorKey>& akeys ) {
glm::vec3 SrcAnimKeyCollection::getVec3ForTime( const float& atime, const std::vector<ofxAssimp::AnimVectorKey>& akeys ) {
size_t numKeys = akeys.size();
for( size_t i = 0; i < numKeys; i++ ) {
if( akeys[i].time == atime ) {
Expand Down Expand Up @@ -108,7 +103,7 @@ std::vector<AnimVectorKey> SrcAnimKeyCollection::getAnimVectorKeysForTime(const
if(aNumKeys == 1) {
AnimVectorKey vkey;
vkey.time = aStartTime;
vkey.value = aiVecToOfVec(aAiKeys[0].mValue);
vkey.value = ofxAssimp::Utils::aiVecToOfVec(aAiKeys[0].mValue);
vkey.valueAi = aAiKeys[0].mValue;
rkeys.push_back( vkey );
return rkeys;
Expand All @@ -117,7 +112,7 @@ std::vector<AnimVectorKey> SrcAnimKeyCollection::getAnimVectorKeysForTime(const
double currTime = aStartTime;
for( unsigned int i = 0; i < aNumKeys; i++ ) {
auto& key1 = aAiKeys[i];
auto v1 = aiVecToOfVec(key1.mValue);
auto v1 = ofxAssimp::Utils::aiVecToOfVec(key1.mValue);
AnimVectorKey vkey;
vkey.time = key1.mTime;
vkey.value = v1;
Expand All @@ -138,15 +133,15 @@ std::vector<AnimRotationKey> SrcAnimKeyCollection::getAnimRotationKeysForTime(co
if(aNumKeys == 1) {
AnimRotationKey vkey;
vkey.time = aStartTime;
vkey.value = aiQuatToOfQuat(aAiKeys[0].mValue);
vkey.value = ofxAssimp::Utils::aiQuatToOfQuat(aAiKeys[0].mValue);
vkey.valueAi = aAiKeys[0].mValue;
rkeys.push_back( vkey );
return rkeys;
}
double currTime = aStartTime;
for( unsigned int i = 0; i < aNumKeys; i++ ) {
auto& key1 = aAiKeys[i];
auto v1 = aiQuatToOfQuat(key1.mValue);
auto v1 = ofxAssimp::Utils::aiQuatToOfQuat(key1.mValue);
AnimRotationKey vkey;
vkey.time = key1.mTime;
vkey.value = v1;
Expand Down
10 changes: 5 additions & 5 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcAnimKeyCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ofNode.h"


namespace ofx::assimp {
namespace ofxAssimp {

struct AnimVectorKey {
float time = 0.0;
Expand All @@ -26,9 +26,9 @@ class SrcAnimKeyCollection {
public:
unsigned int uId = 0;
std::string name = "";
std::vector<ofx::assimp::AnimVectorKey> positionKeys;
std::vector<ofx::assimp::AnimRotationKey> rotationKeys;
std::vector<ofx::assimp::AnimVectorKey> scaleKeys;
std::vector<ofxAssimp::AnimVectorKey> positionKeys;
std::vector<ofxAssimp::AnimRotationKey> rotationKeys;
std::vector<ofxAssimp::AnimVectorKey> scaleKeys;

void clear() {
positionKeys.clear();
Expand All @@ -39,7 +39,7 @@ class SrcAnimKeyCollection {
void setup( aiNodeAnim* aNodeAnim, float aDurationInTicks );
bool hasKeys();

glm::vec3 getVec3ForTime( const float& atime, const std::vector<ofx::assimp::AnimVectorKey>& akeys );
glm::vec3 getVec3ForTime( const float& atime, const std::vector<ofxAssimp::AnimVectorKey>& akeys );

glm::vec3 getPosition( const float& atime );
glm::vec3 getScale( const float& atime );
Expand Down
6 changes: 3 additions & 3 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcBone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "of3dUtils.h"
#include "ofxAssimpUtils.h"

using namespace ofx::assimp;
using namespace ofxAssimp;

//--------------------------------------------------------------
void SrcBone::setAiBone(aiBone* aAiBone, aiNode* aAiNode) {
Expand Down Expand Up @@ -118,8 +118,8 @@ void SrcBone::setAiBone(aiBone* aAiBone, aiNode* aAiNode) {
//}

//--------------------------------------------------------------
std::shared_ptr<ofx::assimp::SrcBone> SrcBone::getBone( aiNode* aAiNode ) {
std::shared_ptr<ofx::assimp::SrcBone> tbone;
std::shared_ptr<ofxAssimp::SrcBone> SrcBone::getBone( aiNode* aAiNode ) {
std::shared_ptr<ofxAssimp::SrcBone> tbone;
findBoneRecursive( aAiNode, tbone );
if( tbone ) {
return tbone;
Expand Down
8 changes: 4 additions & 4 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcBone.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#pragma once
#include "ofxAssimpSrcNode.h"

namespace ofx::assimp {
class SrcBone : public ofx::assimp::SrcNode {
namespace ofxAssimp {
class SrcBone : public ofxAssimp::SrcNode {
public:
virtual NodeType getType() override { return OFX_ASSIMP_BONE; }

void setAiBone(aiBone* aAiBone, aiNode* aAiNode);
// void update();

std::shared_ptr<ofx::assimp::SrcBone> getBone( aiNode* aAiNode );
std::shared_ptr<ofxAssimp::SrcBone> getBone( aiNode* aAiNode );
void findBoneRecursive( aiNode* aAiNode, std::shared_ptr<SrcBone>& returnBone );

std::string getAsString( unsigned int aLevel=0 );
Expand All @@ -29,7 +29,7 @@ class SrcBone : public ofx::assimp::SrcNode {
// aiMatrix4x4& getAiMatrixGlobal() { return mAiMatrixGlobal; }
aiMatrix4x4& getAiOffsetMatrix() { return mOffsetMatrix;}

std::vector< std::shared_ptr<ofx::assimp::SrcBone> > childBones;
std::vector< std::shared_ptr<ofxAssimp::SrcBone> > childBones;

protected:
aiBone* mAiBone = nullptr;
Expand Down
33 changes: 13 additions & 20 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcMesh.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// ofxAssimpSrcMesh.cpp
// ofxAssimpExample
//
// Created by Nick Hardeman on 10/24/23.
//

#include "ofxAssimpSrcMesh.h"
#include "ofxAssimpUtils.h"
#include "of3dGraphics.h"
Expand All @@ -13,23 +6,23 @@
using std::make_shared;
using std::shared_ptr;

using namespace ofx::assimp;
using namespace ofxAssimp;

static unsigned int sUniqueMeshCounter = 0;
ofTexture SrcMesh::sDummyTex;

//-------------------------------------------
void SrcMesh::addTexture( std::shared_ptr<ofx::assimp::Texture> aAssimpTex){
void SrcMesh::addTexture( std::shared_ptr<ofxAssimp::Texture> aAssimpTex){

if(!material) {
material = std::make_shared<ofMaterial>();
}

auto tAiType = aAssimpTex->getAiTextureType();
auto tofType = ofx::assimp::Texture::ofTextureTypeForAiType(tAiType);
auto tofType = ofxAssimp::Texture::ofTextureTypeForAiType(tAiType);

if(tofType == OF_MATERIAL_TEXTURE_NONE ) {
ofLogError("ofx::assimp::Mesh::addTexture") << aAssimpTex->getAiTextureTypeAsString();
ofLogError("ofxAssimp::Mesh::addTexture") << aAssimpTex->getAiTextureTypeAsString();
return;
}

Expand Down Expand Up @@ -70,7 +63,7 @@ bool SrcMesh::hasTexture(aiTextureType aTexType){

//-------------------------------------------
bool SrcMesh::hasTexture(ofMaterialTextureType aType){
return hasTexture( ofx::assimp::Texture::aiTextureTypeForOfType(aType));
return hasTexture( ofxAssimp::Texture::aiTextureTypeForOfType(aType));
}

//-------------------------------------------
Expand All @@ -80,13 +73,13 @@ std::size_t SrcMesh::getNumTextures() {

//-------------------------------------------
ofTexture& SrcMesh::getTexture() {
for( auto iter = ofx::assimp::Texture::sAiTexTypeToOfTexTypeMap.begin(); iter != ofx::assimp::Texture::sAiTexTypeToOfTexTypeMap.end(); iter++ ) {
for( auto iter = ofxAssimp::Texture::sAiTexTypeToOfTexTypeMap.begin(); iter != ofxAssimp::Texture::sAiTexTypeToOfTexTypeMap.end(); iter++ ) {
if( hasTexture((aiTextureType)iter->first) ) {
return getTexture((aiTextureType)iter->first);
}
}

ofLogWarning("ofx::assimp::Mesh::getTexture") << " unable to find any allocated texture";
ofLogWarning("ofxAssimp::Mesh::getTexture") << " unable to find any allocated texture";
return sDummyTex;
}

Expand All @@ -97,13 +90,13 @@ ofTexture& SrcMesh::getTexture(aiTextureType aTexType){
return tex->getTextureRef();
}
}
ofLogWarning("ofx::assimp::SrcMesh::getTexture : unable to find texture ref for ") << aTexType;
ofLogWarning("ofxAssimp::SrcMesh::getTexture : unable to find texture ref for ") << aTexType;
return sDummyTex;
}

//-------------------------------------------
ofTexture& SrcMesh::getTexture(ofMaterialTextureType aType){
return getTexture( ofx::assimp::Texture::aiTextureTypeForOfType(aType) );
return getTexture( ofxAssimp::Texture::aiTextureTypeForOfType(aType) );
}

//-------------------------------------------
Expand Down Expand Up @@ -132,9 +125,9 @@ void SrcMesh::setAiMesh( aiMesh* amesh, aiNode* aAiNode ) {
void SrcMesh::setupVbo( std::shared_ptr<ofVbo> avbo ) {
ofMesh tempMesh;
if( hasTexture() ) {
aiMeshToOfMesh(mAiMesh, tempMesh, !bConvertedToLeftHand, &getTexture() );
ofxAssimp::Utils::aiMeshToOfMesh(mAiMesh, tempMesh, !bConvertedToLeftHand, &getTexture() );
} else {
aiMeshToOfMesh(mAiMesh, tempMesh, !bConvertedToLeftHand, nullptr);
ofxAssimp::Utils::aiMeshToOfMesh(mAiMesh, tempMesh, !bConvertedToLeftHand, nullptr);
}

avbo->setVertexData(&mAiMesh->mVertices[0].x,3,mAiMesh->mNumVertices,usage,sizeof(aiVector3D));
Expand Down Expand Up @@ -164,9 +157,9 @@ void SrcMesh::setupVbo( std::shared_ptr<ofVbo> avbo ) {
void SrcMesh::setMeshFromAiMesh( ofMesh& amesh ) {
if( mAiMesh != NULL && amesh.getNumVertices() < 1 ) {
if( hasTexture() ) {
aiMeshToOfMesh(mAiMesh, amesh, !bConvertedToLeftHand, &getTexture());
ofxAssimp::Utils::aiMeshToOfMesh(mAiMesh, amesh, !bConvertedToLeftHand, &getTexture());
} else {
aiMeshToOfMesh(mAiMesh, amesh, !bConvertedToLeftHand, nullptr);
ofxAssimp::Utils::aiMeshToOfMesh(mAiMesh, amesh, !bConvertedToLeftHand, nullptr);
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcMesh.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// ofxAssimpSrcMesh.h
// ofxAssimpExample
//
// Created by Nick Hardeman on 10/24/23.
//
Expand All @@ -12,13 +11,13 @@
#include "ofVbo.h"
#include "ofxAssimpBounds.h"

namespace ofx::assimp {
class SrcMesh : public ofx::assimp::SrcNode {
namespace ofxAssimp {
class SrcMesh : public ofxAssimp::SrcNode {
public:
static ofTexture sDummyTex;
virtual NodeType getType() override { return OFX_ASSIMP_MESH; }

void addTexture(std::shared_ptr<ofx::assimp::Texture> aAssimpTex);
void addTexture(std::shared_ptr<ofxAssimp::Texture> aAssimpTex);
bool hasTexture();
bool hasTexture(aiTextureType aTexType);
bool hasTexture( ofMaterialTextureType aType );
Expand All @@ -27,7 +26,7 @@ class SrcMesh : public ofx::assimp::SrcNode {
ofTexture& getTexture();
ofTexture& getTexture(aiTextureType aTexType);
ofTexture& getTexture(ofMaterialTextureType aType);
std::vector<std::shared_ptr<ofx::assimp::Texture>> & getAllMeshTextures(){ return meshTextures; }
std::vector<std::shared_ptr<ofxAssimp::Texture>> & getAllMeshTextures(){ return meshTextures; }

void setAiMesh(aiMesh* amesh, aiNode* aAiNode);
aiMesh* getAiMesh() { return mAiMesh; }
Expand All @@ -51,6 +50,6 @@ class SrcMesh : public ofx::assimp::SrcNode {
protected:
aiMesh* mAiMesh = nullptr; // pointer to the aiMesh we represent.
Bounds mLocalBounds;
std::vector<std::shared_ptr<ofx::assimp::Texture>> meshTextures;
std::vector<std::shared_ptr<ofxAssimp::Texture>> meshTextures;
};
}
20 changes: 10 additions & 10 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

static unsigned int sUniqueIdCounter = 0;

using namespace ofx::assimp;
using namespace ofxAssimp;

//--------------------------------------------------------------
std::string SrcNode::sGetNodeTypeAsString( const NodeType& atype ) {
Expand All @@ -12,8 +12,8 @@ std::string SrcNode::sGetNodeTypeAsString( const NodeType& atype ) {
return "OFX_ASSIMP_BONE";
} else if(atype == OFX_ASSIMP_SKELETON ) {
return "OFX_ASSIMP_SKELETON";
} else if(atype == OFX_ASSIMP_MODEL ) {
return "OFX_ASSIMP_MODEL";
} else if(atype == OFX_ASSIMP_SCENE ) {
return "OFX_ASSIMP_SCENE";
}
return "OFX_ASSIMP_NODE";
}
Expand All @@ -26,8 +26,8 @@ std::string SrcNode::sGetNodeTypeShortAsString( const NodeType& atype ) {
return "BONE";
} else if(atype == OFX_ASSIMP_SKELETON ) {
return "SKELETON";
} else if(atype == OFX_ASSIMP_MODEL ) {
return "MODEL";
} else if(atype == OFX_ASSIMP_SCENE ) {
return "SCENE";
}
return "NODE";
}
Expand All @@ -53,8 +53,8 @@ std::string SrcNode::getName() {
}

//----------------------------------------
std::shared_ptr<ofx::assimp::SrcNode> SrcNode::getNode( aiNode* aAiNode ) {
std::shared_ptr<ofx::assimp::SrcNode> tnode;
std::shared_ptr<ofxAssimp::SrcNode> SrcNode::getNode( aiNode* aAiNode ) {
std::shared_ptr<ofxAssimp::SrcNode> tnode;
findNodeRecursive( aAiNode, tnode );
return tnode;
}
Expand All @@ -73,8 +73,8 @@ void SrcNode::findNodeRecursive( aiNode* aAiNode, std::shared_ptr<SrcNode>& aRet
}

//----------------------------------------
std::shared_ptr<ofx::assimp::SrcNode> SrcNode::getNode( const std::string& aAiNodeName ) {
std::shared_ptr<ofx::assimp::SrcNode> tnode;
std::shared_ptr<ofxAssimp::SrcNode> SrcNode::getNode( const std::string& aAiNodeName ) {
std::shared_ptr<ofxAssimp::SrcNode> tnode;
findNodeRecursive( aAiNodeName, tnode );
return tnode;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ std::string SrcNode::getAsString( int aLevel ) {

// animation functions
//--------------------------------------------------------------
ofx::assimp::SrcAnimKeyCollection& SrcNode::getKeyCollection(unsigned int aAnimUId){
ofxAssimp::SrcAnimKeyCollection& SrcNode::getKeyCollection(unsigned int aAnimUId){
if( mKeyCollections.count(aAnimUId) < 1 ) {
SrcAnimKeyCollection temp;
temp.uId = aAnimUId;
Expand Down
18 changes: 9 additions & 9 deletions addons/ofxAssimp/src/Source/ofxAssimpSrcNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <assimp/scene.h>
#include <unordered_map>

namespace ofx::assimp {
namespace ofxAssimp {
enum NodeType {
OFX_ASSIMP_MESH=0,
OFX_ASSIMP_BONE,
OFX_ASSIMP_SKELETON,
OFX_ASSIMP_NODE,
OFX_ASSIMP_MODEL
OFX_ASSIMP_SCENE
};

class SrcNode {
Expand All @@ -31,27 +31,27 @@ class SrcNode {

aiNode* getAiNode() { return mAiNode; }

std::shared_ptr<ofx::assimp::SrcNode> getNode( aiNode* aAiNode );
std::shared_ptr<ofxAssimp::SrcNode> getNode( aiNode* aAiNode );
void findNodeRecursive( aiNode* aAiNode, std::shared_ptr<SrcNode>& aReturnNode );

std::shared_ptr<ofx::assimp::SrcNode> getNode( const std::string& aAiNodeName );
std::shared_ptr<ofxAssimp::SrcNode> getNode( const std::string& aAiNodeName );
void findNodeRecursive( const std::string& aAiNodeName, std::shared_ptr<SrcNode>& aReturnNode );

void clearChildren();
void addChild( std::shared_ptr<ofx::assimp::SrcNode> akiddo );
void addChild( std::shared_ptr<ofxAssimp::SrcNode> akiddo );
unsigned int getNumChildren();
std::vector< std::shared_ptr<ofx::assimp::SrcNode> >& getChildren();
std::vector< std::shared_ptr<ofxAssimp::SrcNode> >& getChildren();

virtual std::string getAsString( int aLevel=0 );

// animation functions
ofx::assimp::SrcAnimKeyCollection& getKeyCollection( unsigned int aAnimUId );
ofxAssimp::SrcAnimKeyCollection& getKeyCollection( unsigned int aAnimUId );

protected:
aiNode* mAiNode = nullptr;
std::string mName = "";
std::vector< std::shared_ptr<ofx::assimp::SrcNode> > mKids;
std::vector< std::shared_ptr<ofxAssimp::SrcNode> > mKids;

std::unordered_map<unsigned int, ofx::assimp::SrcAnimKeyCollection> mKeyCollections;
std::unordered_map<unsigned int, ofxAssimp::SrcAnimKeyCollection> mKeyCollections;
};
}
Loading