framework2

Форк
0
1
#include "ofApp.h"
2

3
//--------------------------------------------------------------
4
void ofApp::setup() {
5
    
6
    ofSetBackgroundColor( 220 );
7
    
8
    ofSetLogLevel( OF_LOG_VERBOSE );
9
    
10
    ofSetFrameRate(60);
11
    
12
    ofDisableArbTex();
13
    if(!ofLoadImage(teddyTex, "tex.png" )) {
14
        ofLogError("Could not load tex.png texture");
15
    }
16
    
17
    ofxFBXSource::Scene::Settings settings;
18
    settings.importTextures = false;
19
    settings.importMaterials = false;
20
    // must use keyframes when blending animations //
21
    settings.useKeyFrames = true; // on by default //
22
    // model from https://www.turbosquid.com/FullPreview/Index.cfm/ID/615227
23
    settings.filePath = "teddy.fbx";
24
    // we don't want to manipulate the bones, so caching the meshes will reduce the bone transform calls
25
    // and should speed it up with a lot of the same animated meshes that have bones //
26
    settings.cacheMeshKeyframes = true;
27
    
28
    cam.lookAt( ofVec3f(0,0,0) );
29
    cam.setDistance( 550 );
30
    cam.setFarClip(6000);
31
    cam.setNearClip( .5f );
32
    
33
//    fbxMan.setup( &scene );
34
    fbx.load( settings );
35
    fbx.setAnimation(0);
36
    fbx.setScale( 0.15 );
37
    fbx.setPosition(-150, 0, 0 );
38
//    fbx.cacheMeshKeyframes(true);
39
    
40
//    fbxManSmooth.setup( &scene );
41
    fbxSmooth.load( settings );
42
    fbxSmooth.setAnimation(0);
43
    fbxSmooth.setScale( 0.15 );
44
    fbxSmooth.setPosition( 150, 0, 0 );
45
//    fbxSmooth.cacheMeshKeyframes(true);
46
    
47
    for( int i = 0; i < fbx.getNumMeshes(); i++ ) {
48
        cout << i << " - " << " num tex coords: " << fbx.getMeshes()[i]->getMesh().getNumTexCoords() << endl;
49
        
50
    }
51
    fbx.setMaterialsEnabled(false);
52
    
53
    bRenderNormals  = false;
54
}
55

56
//--------------------------------------------------------------
57
void ofApp::update() {
58
    
59
    fbx.earlyUpdate();
60
    
61
    // align the meshes with y axis //
62
    for( int i = 0; i < fbx.getMeshes().size(); i++ ) {
63
        fbx.getMeshes()[i]->panDeg(-90);
64
    }
65
    
66
    if( fbx.getCurrentAnimation().name == "walk" ) {
67
        fbx.panDeg( 1 );
68
    }
69
    fbx.lateUpdate();
70
    
71
    // update internally calls earlyUpdate and then lateUpdate
72
    fbxSmooth.update();
73
    
74
    // align the meshes with y axis //
75
    for( int i = 0; i < fbxSmooth.getMeshes().size(); i++ ) {
76
        fbxSmooth.getMeshes()[i]->panDeg(-90);
77
    }
78
    
79
    if( fbxSmooth.getCurrentAnimation().name == "walk" ) {
80
        if(!fbxSmooth.isTransitioning()) fbxSmooth.panDeg( 1 );
81
    }
82
    
83
}
84

85
//--------------------------------------------------------------
86
void ofApp::draw() {
87
    
88
    ofSetColor(255, 255, 255);
89
    // this causes the texture not to render on the models on iOS
90
    #ifndef TARGET_OPENGLES
91
    ofBackgroundGradient( ofColor::white, ofColor::gray );
92
    #endif
93
    
94
    ofEnableDepthTest();
95
    cam.begin(); {
96
        // this causes the texture not to render on the models on iOS
97
        #ifndef TARGET_OPENGLES
98
        ofSetColor( 160 );
99
        ofPushMatrix(); {
100
            ofTranslate( 0, -150, 0 );
101
            ofRotateYDeg(90);
102
            ofRotateZDeg(90);
103
        //    float stepSize = 1.25f, size_t numberOfSteps = 8, bool labels = false
104
            ofDrawGridPlane(40, 50, false );
105
        } ofPopMatrix();
106
        #endif
107
        
108
        ofEnableLighting();
109
        light.enable();
110
        
111
        ofSetColor( 200 );
112
        teddyTex.bind();
113
        fbx.draw();
114
        fbxSmooth.draw();
115
        teddyTex.unbind();
116
        
117
        light.disable();
118
        ofDisableLighting();
119
        
120
        
121
        if( bRenderNormals ) {
122
            ofSetColor( 255, 0, 255 );
123
            fbx.drawMeshNormals( 0.1, false );
124
        }
125
        
126
        
127
        ofSetColor( light.getDiffuseColor() );
128
        light.draw();
129
        
130
    } cam.end();
131
    
132
    ofDisableDepthTest();
133
    
134
    int numBones = fbx.getNumBones();
135
    
136
    ofSetColor( 60, 60, 60 );
137
    stringstream ds;
138
    ds << "Render normals (n): " << bRenderNormals << endl;
139
    ds << "Render " << numBones << " bones " << endl;
140
    if( fbx.areAnimationsEnabled() ) {
141
        ds << "Toggle play/pause (spacebar): playing: " << fbx.getCurrentAnimation().isPlaying() << endl;
142
        ds << "Previous/Next animation (up/down): " << fbx.getCurrentAnimation().name << endl;
143
    }
144
//    ds << "Scale is " << fbxMan.getScale() << endl;
145
//    if( fbxMan.getNumPoses() > 0 ) {
146
//        ds << "Pose: " << fbxMan.getCurrentPose()->getName() << " num poses: " << fbxMan.getNumPoses() << " enabled (p): " << fbxMan.arePosesEnabled() << endl;
147
//    }
148
    ofDrawBitmapString( ds.str(), 50, 30 );
149
    
150
    
151
    for(int i = 0; i < fbx.getNumAnimations(); i++ ) {
152
        stringstream ss;
153
        ofxFBXAnimation& anim = fbx.getAnimation( i );
154
        if( i == fbx.getCurrentAnimationIndex() ) {
155
            ss << "- ";
156
        }
157
        ss << "name: " << anim.name << " " << ofToString(anim.getPositionSeconds(), 3) << " | " << ofToString(anim.getDurationSeconds(), 3) << " frame: " << anim.getFrameNum() << " / " << anim.getTotalNumFrames() << endl;
158
        ofDrawBitmapString( ss.str(), 50, i * 30 + 650 );
159
    }
160
    
161
    stringstream fs;
162
    fs << "TEDDY SMOOOOOTH" << endl;
163
    fs << "transition: " << ofToString(fbxSmooth.getTransition().percent* 100.0, 0) << "% " << " is transitioning: " << fbxSmooth.isTransitioning() << endl;
164
    ofDrawBitmapString( fs.str(), ofGetWidth()/2 + 200, 650 );
165
}
166

167
#ifdef TARGET_OPENGLES
168
//--------------------------------------------------------------
169
void ofApp::touchDown(ofTouchEventArgs & touch) {
170
    
171
}
172

173
//--------------------------------------------------------------
174
void ofApp::touchMoved(ofTouchEventArgs & touch) {
175
    
176
}
177

178
//--------------------------------------------------------------
179
void ofApp::touchUp(ofTouchEventArgs & touch) {
180
    
181
}
182

183
//--------------------------------------------------------------
184
void ofApp::touchDoubleTap(ofTouchEventArgs & touch) {
185
    if(fbx.getNumAnimations() > 1) {
186
        int newAnimIndex = fbx.getCurrentAnimationIndex()+1;
187
        if(newAnimIndex > fbx.getNumAnimations()-1 ) {
188
            newAnimIndex = 0;
189
        }
190
        fbx.setAnimation( newAnimIndex );
191
        fbxSmooth.transition( newAnimIndex, 1.f );
192
    }
193
}
194

195
//--------------------------------------------------------------
196
void ofApp::touchCancelled(ofTouchEventArgs & touch) {
197
    
198
}
199
#else
200

201
//--------------------------------------------------------------
202
void ofApp::keyPressed(int key) {
203
    if(fbx.getNumAnimations() > 1) {
204
        if(key == OF_KEY_DOWN ) {
205
            int newAnimIndex = fbx.getCurrentAnimationIndex()+1;
206
            if(newAnimIndex > fbx.getNumAnimations()-1 ) {
207
                newAnimIndex = 0;
208
            }
209
            fbx.setAnimation( newAnimIndex );
210
            fbxSmooth.transition( newAnimIndex, 1.f );
211
            
212
        }
213
        if(key == OF_KEY_UP ) {
214
            int newAnimIndex = fbx.getCurrentAnimationIndex()-1;
215
            if(newAnimIndex < 0 ) {
216
                newAnimIndex = fbx.getNumAnimations()-1;
217
            }
218
            fbx.setAnimation( newAnimIndex );
219
            fbxSmooth.transition( newAnimIndex, 1.f );
220
        }
221
    }
222
}
223

224
//--------------------------------------------------------------
225
void ofApp::keyReleased(int key) {
226
    if(key == ' ') {
227
        fbx.getCurrentAnimation().togglePlayPause();
228
    }
229
    if(key == 'n') {
230
        bRenderNormals = !bRenderNormals;
231
    }
232
}
233

234
//--------------------------------------------------------------
235
void ofApp::mouseMoved(int x, int y) {
236
    
237
}
238

239
//--------------------------------------------------------------
240
void ofApp::mouseDragged(int x, int y, int button) {
241
    
242
}
243

244
//--------------------------------------------------------------
245
void ofApp::mousePressed(int x, int y, int button)    {
246
    
247
}
248

249
//--------------------------------------------------------------
250
void ofApp::mouseReleased(int x, int y, int button) {
251
    
252
}
253

254
//--------------------------------------------------------------
255
void ofApp::windowResized(int w, int h) {
256
    
257
}
258

259
//--------------------------------------------------------------
260
void ofApp::gotMessage(ofMessage msg) {
261
    
262
}
263

264
//--------------------------------------------------------------
265
void ofApp::dragEvent(ofDragInfo dragInfo) {
266
    
267
}
268
#endif
269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

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

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

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

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