Skip to content

Commit dd09e97

Browse files
authored
Addon - ofxAssimp (#7776)
1 parent 3fccc6d commit dd09e97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+10414
-0
lines changed

addons/ofxAssimp/addon_config.mk

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# All variables and this file are optional, if they are not present the PG and the
2+
# makefiles will try to parse the correct values from the file system.
3+
#
4+
# Variables that specify exclusions can use % as a wildcard to specify that anything in
5+
# that position will match. A partial path can also be specified to, for example, exclude
6+
# a whole folder from the parsed paths from the file system
7+
#
8+
# Variables can be specified using = or +=
9+
# = will clear the contents of that variable both specified from the file or the ones parsed
10+
# from the file system
11+
# += will add the values to the previous ones in the file or the ones parsed from the file
12+
# system
13+
#
14+
# The PG can be used to detect errors in this file, just create a new project with this addon
15+
# and the PG will write to the console the kind of error and in which line it is
16+
17+
meta:
18+
ADDON_NAME = ofxAssimp
19+
ADDON_DESCRIPTION = Addon for loading several 3d formats through the assimp library
20+
ADDON_AUTHOR = OF Team
21+
ADDON_TAGS = "3D" "assimp"
22+
ADDON_URL = http://github.com/openframeworks/openFrameworks
23+
24+
common:
25+
# dependencies with other addons, a list of them separated by spaces
26+
# or use += in several lines
27+
# ADDON_DEPENDENCIES =
28+
29+
# include search paths, this will be usually parsed from the file system
30+
# but if the addon or addon libraries need special search paths they can be
31+
# specified here separated by spaces or one per line using +=
32+
ADDON_INCLUDES+=../ofxAssimpModelLoader/libs/assimp/include/
33+
34+
# any special flag that should be passed to the compiler when using this
35+
# addon
36+
# ADDON_CFLAGS =
37+
38+
# any special flag that should be passed to the linker when using this
39+
# addon, also used for system libraries with -lname
40+
# ADDON_LDFLAGS =
41+
42+
# linux only, any library that should be included in the project using
43+
# pkg-config
44+
# ADDON_PKG_CONFIG_LIBRARIES =
45+
46+
# osx/iOS only, any framework that should be included in the project
47+
# ADDON_FRAMEWORKS =
48+
49+
# source files, these will be usually parsed from the file system looking
50+
# in the src folders in libs and the root of the addon. if your addon needs
51+
# to include files in different places or a different set of files per platform
52+
# they can be specified here
53+
# ADDON_SOURCES =
54+
55+
# some addons need resources to be copied to the bin/data folder of the project
56+
# specify here any files that need to be copied, you can use wildcards like * and ?
57+
# ADDON_DATA =
58+
59+
# when parsing the file system looking for libraries exclude this for all or
60+
# a specific platform
61+
# ADDON_LIBS_EXCLUDE =
62+
63+
linuxarmv6l:
64+
ADDON_PKG_CONFIG_LIBRARIES = assimp
65+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
66+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
67+
68+
linuxarmv7l:
69+
ADDON_PKG_CONFIG_LIBRARIES = assimp
70+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
71+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
72+
73+
linuxaarch64:
74+
ADDON_PKG_CONFIG_LIBRARIES = assimp
75+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
76+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
77+
78+
linux:
79+
ADDON_PKG_CONFIG_LIBRARIES = assimp
80+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
81+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
82+
83+
linux64:
84+
ADDON_PKG_CONFIG_LIBRARIES = assimp
85+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
86+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
87+
88+
msys2:
89+
ADDON_PKG_CONFIG_LIBRARIES = assimp
90+
ADDON_LIBS_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp
91+
ADDON_INCLUDES_EXCLUDE = ../ofxAssimpModelLoader/libs/assimp/%
92+
93+
android/armeabi-v7a:
94+
ADDON_LIBS=
95+
ADDON_LIBS+=../ofxAssimpModelLoader/libs/assimp/lib/android/armeabi-v7a/libassimp.a
96+
ADDON_LIBS+=../ofxAssimpModelLoader/libs/assimp/lib/android/armeabi-v7a/libIrrXML.a
97+
98+
android/x86:
99+
ADDON_LIBS=
100+
ADDON_LIBS+=../ofxAssimpModelLoader/libs/assimp/lib/android/x86/libassimp.a
101+
ADDON_LIBS+=../ofxAssimpModelLoader/libs/assimp/lib/android/x86/libIrrXML.a
102+
103+
ios:
104+
ADDON_LIBS=
105+
ADDON_LIBS=../ofxAssimpModelLoader/libs/assimp/lib/ios/assimp.a
106+
107+
osx:
108+
ADDON_LIBS=
109+
ADDON_LIBS=../ofxAssimpModelLoader/libs/assimp/lib/osx/assimp.a
110+
111+
emscripten:
112+
ADDON_LIBS=
113+
ADDON_LIBS=../ofxAssimpModelLoader/libs/assimp/lib/emscripten/libassimp.a
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
//
2+
// ofxAssimpSrcAnimKeyCollection.cpp
3+
// Created by Nick Hardeman on 11/1/23.
4+
//
5+
6+
#include "ofxAssimpSrcAnimKeyCollection.h"
7+
#include "ofxAssimpUtils.h"
8+
9+
using namespace ofx::assimp;
10+
11+
//--------------------------------------------------------------
12+
void SrcAnimKeyCollection::setup( aiNodeAnim* aNodeAnim, float aDurationInTicks ) {
13+
mNodeAnim = aNodeAnim;
14+
mDurationInTicks = aDurationInTicks;
15+
}
16+
17+
//--------------------------------------------------------------
18+
bool SrcAnimKeyCollection::hasKeys() {
19+
return mNodeAnim != nullptr;
20+
}
21+
22+
23+
//--------------------------------------------------------------
24+
glm::vec3 SrcAnimKeyCollection::getVec3ForTime( const float& atime, const std::vector<ofx::assimp::AnimVectorKey>& akeys ) {
25+
size_t numKeys = akeys.size();
26+
for( size_t i = 0; i < numKeys; i++ ) {
27+
if( akeys[i].time == atime ) {
28+
return akeys[i].value;
29+
} else if( akeys[i].time > atime ) {
30+
if( i > 0 ) {
31+
float keyDiff = akeys[i].time - akeys[i-1].time;
32+
return glm::mix( akeys[i-1].value, akeys[i].value, (atime-akeys[i-1].time) / keyDiff );
33+
} else {
34+
return akeys[i].value;
35+
}
36+
}
37+
}
38+
if( numKeys > 1 ) {
39+
return akeys.back().value;
40+
}
41+
return glm::vec3(0.f, 0.f, 0.f);
42+
}
43+
44+
//--------------------------------------------------------------
45+
glm::vec3 SrcAnimKeyCollection::getPosition( const float& atime ) {
46+
auto rpos = glm::vec3(0.f, 0.f, 0.f);
47+
if( positionKeys.size() < 1 ) {
48+
49+
} else if( positionKeys.size() == 1 ) {
50+
rpos = positionKeys[0].value;
51+
} else {
52+
rpos = getVec3ForTime( atime, positionKeys );
53+
}
54+
return rpos;
55+
}
56+
57+
//--------------------------------------------------------------
58+
glm::vec3 SrcAnimKeyCollection::getScale( const float& atime ) {
59+
auto rscale = glm::vec3(1.f, 1.f, 1.f);
60+
if( scaleKeys.size() < 1 ) {
61+
62+
} else if(scaleKeys.size() == 1 ) {
63+
rscale = scaleKeys[0].value;
64+
} else {
65+
rscale = getVec3ForTime( atime, scaleKeys );
66+
}
67+
return rscale;
68+
}
69+
70+
//--------------------------------------------------------------
71+
glm::quat SrcAnimKeyCollection::getRotation( const float& atime ) {
72+
size_t numKeys = rotationKeys.size();
73+
auto rq = glm::quat(1.f, 0.f, 0.f, 0.f);
74+
if(numKeys < 2) {
75+
if( numKeys == 1 ) {
76+
return rotationKeys[0].value;
77+
} else {
78+
return rq;
79+
}
80+
} else {
81+
for( size_t i = 0; i < numKeys; i++ ) {
82+
if( rotationKeys[i].time == atime ) {
83+
return rotationKeys[i].value;
84+
} else if( rotationKeys[i].time > atime ) {
85+
if( i > 0 ) {
86+
float keyDiff = rotationKeys[i].time - rotationKeys[i-1].time;
87+
return glm::slerp( rotationKeys[i-1].value, rotationKeys[i].value, ((atime-rotationKeys[i-1].time) / keyDiff) );
88+
} else {
89+
return rotationKeys[i].value;
90+
}
91+
}
92+
}
93+
}
94+
if( numKeys > 1 ) {
95+
return rotationKeys.back().value;
96+
}
97+
return rq;
98+
}
99+
100+
//--------------------------------------------------------------
101+
std::vector<AnimVectorKey> SrcAnimKeyCollection::getAnimVectorKeysForTime(const float& aStartTime, const float& aEndTime, unsigned int aNumKeys, aiVectorKey* aAiKeys) {
102+
103+
std::vector<AnimVectorKey> rkeys;
104+
if( aNumKeys < 1 ) {
105+
return rkeys;
106+
}
107+
108+
if(aNumKeys == 1) {
109+
AnimVectorKey vkey;
110+
vkey.time = aStartTime;
111+
vkey.value = aiVecToOfVec(aAiKeys[0].mValue);
112+
vkey.valueAi = aAiKeys[0].mValue;
113+
rkeys.push_back( vkey );
114+
return rkeys;
115+
}
116+
117+
double currTime = aStartTime;
118+
for( unsigned int i = 0; i < aNumKeys; i++ ) {
119+
auto& key1 = aAiKeys[i];
120+
auto v1 = aiVecToOfVec(key1.mValue);
121+
AnimVectorKey vkey;
122+
vkey.time = key1.mTime;
123+
vkey.value = v1;
124+
vkey.valueAi = key1.mValue;
125+
rkeys.push_back( vkey );
126+
}
127+
128+
return rkeys;
129+
}
130+
131+
//--------------------------------------------------------------
132+
std::vector<AnimRotationKey> SrcAnimKeyCollection::getAnimRotationKeysForTime(const float& aStartTime, const float& aEndTime, unsigned int aNumKeys, aiQuatKey* aAiKeys) {
133+
134+
std::vector<AnimRotationKey> rkeys;
135+
if( aNumKeys < 1 ) {
136+
return rkeys;
137+
}
138+
if(aNumKeys == 1) {
139+
AnimRotationKey vkey;
140+
vkey.time = aStartTime;
141+
vkey.value = aiQuatToOfQuat(aAiKeys[0].mValue);
142+
vkey.valueAi = aAiKeys[0].mValue;
143+
rkeys.push_back( vkey );
144+
return rkeys;
145+
}
146+
double currTime = aStartTime;
147+
for( unsigned int i = 0; i < aNumKeys; i++ ) {
148+
auto& key1 = aAiKeys[i];
149+
auto v1 = aiQuatToOfQuat(key1.mValue);
150+
AnimRotationKey vkey;
151+
vkey.time = key1.mTime;
152+
vkey.value = v1;
153+
vkey.valueAi = key1.mValue;
154+
rkeys.push_back( vkey );
155+
}
156+
157+
return rkeys;
158+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// ofxAssimpSrcAnimKeyCollection.h
3+
// Created by Nick Hardeman on 11/1/23.
4+
//
5+
6+
#pragma once
7+
#include <assimp/scene.h>
8+
#include "ofNode.h"
9+
10+
11+
namespace ofx::assimp {
12+
13+
struct AnimVectorKey {
14+
float time = 0.0;
15+
glm::vec3 value;
16+
aiVector3D valueAi;
17+
};
18+
19+
struct AnimRotationKey {
20+
float time = 0.0;
21+
glm::quat value;
22+
aiQuaternion valueAi;
23+
};
24+
25+
class SrcAnimKeyCollection {
26+
public:
27+
unsigned int uId = 0;
28+
std::string name = "";
29+
std::vector<ofx::assimp::AnimVectorKey> positionKeys;
30+
std::vector<ofx::assimp::AnimRotationKey> rotationKeys;
31+
std::vector<ofx::assimp::AnimVectorKey> scaleKeys;
32+
33+
void clear() {
34+
positionKeys.clear();
35+
rotationKeys.clear();
36+
scaleKeys.clear();
37+
}
38+
39+
void setup( aiNodeAnim* aNodeAnim, float aDurationInTicks );
40+
bool hasKeys();
41+
42+
glm::vec3 getVec3ForTime( const float& atime, const std::vector<ofx::assimp::AnimVectorKey>& akeys );
43+
44+
glm::vec3 getPosition( const float& atime );
45+
glm::vec3 getScale( const float& atime );
46+
glm::quat getRotation( const float& atime );
47+
48+
std::vector<AnimVectorKey> getAnimVectorKeysForTime(const float& aStartTime, const float& aEndTime, unsigned int aNumKeys, aiVectorKey* aAiKeys);
49+
std::vector<AnimRotationKey> getAnimRotationKeysForTime(const float& aStartTime, const float& aEndTime, unsigned int aNumKeys, aiQuatKey* aAiKeys);
50+
51+
52+
aiNodeAnim* mNodeAnim = nullptr;
53+
float mDurationInTicks = 1;
54+
55+
};
56+
}

0 commit comments

Comments
 (0)