framework2

Форк
0
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

12
using namespace ofxFBXSource;
13

14
// from the ViewScene example //
15
// cache the matrices if we are not doing animation //
16
void Cluster::setup(FbxAMatrix& pGlobalPosition,
17
                          FbxMesh* pMesh,
18
                          FbxCluster* pCluster ) {
19
//    FbxAMatrix lReferenceGlobalInitPosition;
20
	FbxAMatrix lReferenceGlobalCurrentPosition;
21
//	FbxAMatrix lAssociateGlobalInitPosition;
22
	FbxAMatrix lAssociateGlobalCurrentPosition;
23
	FbxAMatrix lClusterGlobalInitPosition;
24
	FbxAMatrix lClusterGlobalCurrentPosition;
25
    
26
	FbxAMatrix lReferenceGeometry;
27
	FbxAMatrix lAssociateGeometry;
28
	FbxAMatrix lClusterGeometry;
29
    
30
	FbxAMatrix lClusterRelativeInitPosition;
31
	FbxAMatrix lClusterRelativeCurrentPositionInverse;
32
    
33
    cluster = pCluster;
34
    mesh    = pMesh;
35
    
36
    lClusterGlobalCurrentPosition = GetGlobalPosition( pCluster->GetLink(), FBXSDK_TIME_INFINITE, NULL );
37
    origTransform = lClusterGlobalCurrentPosition;
38
    
39
    FbxCluster::ELinkMode lClusterMode = pCluster->GetLinkMode();
40
    
41
    if (lClusterMode == FbxCluster::eAdditive && pCluster->GetAssociateModel()) {
42
        pCluster->GetTransformAssociateModelMatrix(lAssociateGlobalInitPosition);
43
        // Geometric transform of the model
44
		lAssociateGeometry = GetGeometry(pCluster->GetAssociateModel());
45
		lAssociateGlobalInitPosition *= lAssociateGeometry;
46
		lAssociateGlobalCurrentPosition = GetGlobalPosition( pCluster->GetAssociateModel(), FBXSDK_TIME_INFINITE, NULL );
47
        
48
        pCluster->GetTransformMatrix(lReferenceGlobalInitPosition);
49
		// Multiply lReferenceGlobalInitPosition by Geometric Transformation
50
		lReferenceGeometry = GetGeometry(pMesh->GetNode());
51
		lReferenceGlobalInitPosition *= lReferenceGeometry;
52
		lReferenceGlobalCurrentPosition = pGlobalPosition;
53
        
54
        // Get the link initial global position and the link current global position.
55
		pCluster->GetTransformLinkMatrix( lClusterGlobalInitPosition );
56
		// Multiply lClusterGlobalInitPosition by Geometric Transformation
57
		lClusterGeometry = GetGeometry(pCluster->GetLink());
58
		lClusterGlobalInitPosition *= 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
        
66
        preTrans    = lReferenceGlobalInitPosition.Inverse() * lAssociateGlobalInitPosition * lAssociateGlobalCurrentPosition.Inverse();
67
        postTrans   = lClusterGlobalInitPosition.Inverse() * lReferenceGlobalInitPosition;
68
        
69
    } else {
70
        pCluster->GetTransformMatrix(lReferenceGlobalInitPosition);
71
		lReferenceGlobalCurrentPosition = pGlobalPosition;
72
		// Multiply lReferenceGlobalInitPosition by Geometric Transformation
73
		lReferenceGeometry = GetGeometry(pMesh->GetNode());
74
//        lReferenceGlobalInitPosition = lReferenceGeometry * lReferenceGlobalInitPosition;
75
        lReferenceGlobalInitPosition *= lReferenceGeometry;
76
        
77
		// Get the link initial global position and the link current global position.
78
		pCluster->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
        
88
        preTrans    = lReferenceGlobalCurrentPosition.Inverse();
89
        postTrans   = 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

104
void Cluster::update( FbxTime& pTime , FbxPose* pPose ) {
105
    FbxCluster::ELinkMode lClusterMode = cluster->GetLinkMode();
106
    if (lClusterMode == FbxCluster::eAdditive && cluster->GetAssociateModel()) {
107
        cout << "ofxFBXCluster :: update : cluster mode is eAdditive " << endl;
108
        FbxAMatrix lAssociateGlobalCurrentPosition = GetGlobalPosition( cluster->GetAssociateModel(), pTime, NULL );
109
        preTrans    = lReferenceGlobalInitPosition.Inverse() * lAssociateGlobalInitPosition * lAssociateGlobalCurrentPosition.Inverse();
110
    } else {
111
        cout << "ofxFBXCluster :: update : cluster mode is not eAdditive " << endl;
112
        FbxAMatrix lReferenceGlobalCurrentPosition = GetGlobalPosition( mesh->GetNode(), pTime, NULL );
113
        preTrans    = 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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.