framework2
115 строк · 5.5 Кб
1//
2// ofxFBXCluster.cpp
3// ofxFBX-Example-Importer
4//
5// Created by Nick Hardeman on 11/4/13.
6//
7//
8
9#include "ofxFBXSrcCluster.h"
10#include "ofxFBXUtils.h"
11
12using namespace ofxFBXSource;
13
14// from the ViewScene example //
15// cache the matrices if we are not doing animation //
16void Cluster::setup(FbxAMatrix& pGlobalPosition,
17FbxMesh* pMesh,
18FbxCluster* pCluster ) {
19// FbxAMatrix lReferenceGlobalInitPosition;
20FbxAMatrix lReferenceGlobalCurrentPosition;
21// FbxAMatrix lAssociateGlobalInitPosition;
22FbxAMatrix lAssociateGlobalCurrentPosition;
23FbxAMatrix lClusterGlobalInitPosition;
24FbxAMatrix lClusterGlobalCurrentPosition;
25
26FbxAMatrix lReferenceGeometry;
27FbxAMatrix lAssociateGeometry;
28FbxAMatrix lClusterGeometry;
29
30FbxAMatrix lClusterRelativeInitPosition;
31FbxAMatrix lClusterRelativeCurrentPositionInverse;
32
33cluster = pCluster;
34mesh = pMesh;
35
36lClusterGlobalCurrentPosition = GetGlobalPosition( pCluster->GetLink(), FBXSDK_TIME_INFINITE, NULL );
37origTransform = lClusterGlobalCurrentPosition;
38
39FbxCluster::ELinkMode lClusterMode = pCluster->GetLinkMode();
40
41if (lClusterMode == FbxCluster::eAdditive && pCluster->GetAssociateModel()) {
42pCluster->GetTransformAssociateModelMatrix(lAssociateGlobalInitPosition);
43// Geometric transform of the model
44lAssociateGeometry = GetGeometry(pCluster->GetAssociateModel());
45lAssociateGlobalInitPosition *= lAssociateGeometry;
46lAssociateGlobalCurrentPosition = GetGlobalPosition( pCluster->GetAssociateModel(), FBXSDK_TIME_INFINITE, NULL );
47
48pCluster->GetTransformMatrix(lReferenceGlobalInitPosition);
49// Multiply lReferenceGlobalInitPosition by Geometric Transformation
50lReferenceGeometry = GetGeometry(pMesh->GetNode());
51lReferenceGlobalInitPosition *= lReferenceGeometry;
52lReferenceGlobalCurrentPosition = pGlobalPosition;
53
54// Get the link initial global position and the link current global position.
55pCluster->GetTransformLinkMatrix( lClusterGlobalInitPosition );
56// Multiply lClusterGlobalInitPosition by Geometric Transformation
57lClusterGeometry = GetGeometry(pCluster->GetLink());
58lClusterGlobalInitPosition *= lClusterGeometry;
59// lClusterGlobalCurrentPosition = GetGlobalPosition( pCluster->GetLink(), FBXSDK_TIME_INFINITE, NULL );
60
61// Compute the shift of the link relative to the reference.
62//ModelM-1 * AssoM * AssoGX-1 * LinkGX * LinkM-1*ModelM
63// vertexTransformMatrix = lReferenceGlobalInitPosition.Inverse() * lAssociateGlobalInitPosition * lAssociateGlobalCurrentPosition.Inverse() *
64// lClusterGlobalCurrentPosition * lClusterGlobalInitPosition.Inverse() * lReferenceGlobalInitPosition;
65
66preTrans = lReferenceGlobalInitPosition.Inverse() * lAssociateGlobalInitPosition * lAssociateGlobalCurrentPosition.Inverse();
67postTrans = lClusterGlobalInitPosition.Inverse() * lReferenceGlobalInitPosition;
68
69} else {
70pCluster->GetTransformMatrix(lReferenceGlobalInitPosition);
71lReferenceGlobalCurrentPosition = pGlobalPosition;
72// Multiply lReferenceGlobalInitPosition by Geometric Transformation
73lReferenceGeometry = GetGeometry(pMesh->GetNode());
74// lReferenceGlobalInitPosition = lReferenceGeometry * lReferenceGlobalInitPosition;
75lReferenceGlobalInitPosition *= lReferenceGeometry;
76
77// Get the link initial global position and the link current global position.
78pCluster->GetTransformLinkMatrix(lClusterGlobalInitPosition);
79// lClusterGlobalCurrentPosition = GetGlobalPosition(pCluster->GetLink(), FBXSDK_TIME_INFINITE, NULL );
80
81// Compute the initial position of the link relative to the reference.
82// lClusterRelativeInitPosition = lClusterGlobalInitPosition.Inverse() * lReferenceGlobalInitPosition;
83
84// Compute the current position of the link relative to the reference.
85// lClusterRelativeCurrentPositionInverse = lReferenceGlobalCurrentPosition.Inverse() * lClusterGlobalCurrentPosition;
86
87
88preTrans = lReferenceGlobalCurrentPosition.Inverse();
89postTrans = lClusterGlobalInitPosition.Inverse() * lReferenceGlobalInitPosition;
90
91// preTrans = lReferenceGlobalCurrentPosition;//.Inverse();
92// postTrans = lReferenceGlobalInitPosition.Inverse() * lClusterGlobalInitPosition;
93
94// postTrans = lReferenceGlobalCurrentPosition.Inverse();
95// preTrans = lReferenceGlobalInitPosition.Inverse() * lClusterGlobalInitPosition;
96
97// Compute the shift of the link relative to the reference.
98// vertexTransformMatrix = lClusterRelativeCurrentPositionInverse * lClusterRelativeInitPosition;
99}
100
101}
102
103
104void Cluster::update( FbxTime& pTime , FbxPose* pPose ) {
105FbxCluster::ELinkMode lClusterMode = cluster->GetLinkMode();
106if (lClusterMode == FbxCluster::eAdditive && cluster->GetAssociateModel()) {
107cout << "ofxFBXCluster :: update : cluster mode is eAdditive " << endl;
108FbxAMatrix lAssociateGlobalCurrentPosition = GetGlobalPosition( cluster->GetAssociateModel(), pTime, NULL );
109preTrans = lReferenceGlobalInitPosition.Inverse() * lAssociateGlobalInitPosition * lAssociateGlobalCurrentPosition.Inverse();
110} else {
111cout << "ofxFBXCluster :: update : cluster mode is not eAdditive " << endl;
112FbxAMatrix lReferenceGlobalCurrentPosition = GetGlobalPosition( mesh->GetNode(), pTime, NULL );
113preTrans = lReferenceGlobalCurrentPosition.Inverse();
114}
115}
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138