Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MarchingCubes and MotionVisualization example
- Loading branch information
1 parent
c5f2aaf
commit 53d2f60
Showing
24 changed files
with
1,938 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.svn | ||
.hg | ||
.cvs | ||
|
||
# osx | ||
*.app | ||
*.mode1v3 | ||
*.pbxuser | ||
.DS_Store | ||
build | ||
xcuserdata | ||
DerivedData | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2012 Atsushi Tadokoro (http://yoppa.org/) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
marching-cubes/MarchingCubes.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. | ||
//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED | ||
OF_PATH = ../../.. | ||
|
||
//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE | ||
#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" | ||
|
||
OTHER_LDFLAGS = $(OF_CORE_LIBS) | ||
HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Author | ||
|
||
[Atsushi Tadokoro](http://yoppa.org/) | ||
|
||
## Dependencies | ||
|
||
* [ofxMarchingCubes](http://code.google.com/p/ruicode/downloads/detail?name=ofxMarchingCubes%20002.zip&can=2&q=) | ||
* [ofxSTL](http://code.google.com/p/ruicode/downloads/detail?name=ofxSTL%20001.zip&can=2&q=) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore everything in here apart from the .gitignore file | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.yourcompany.openFrameworks</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "ofMain.h" | ||
#include "ofxMarchingCubes.h" | ||
|
||
class MetaBall: public ofPoint{ | ||
public: | ||
ofPoint accel, vel; | ||
float size; | ||
MetaBall(){ | ||
size = ofRandom(5, 10); | ||
} | ||
|
||
void init(const ofPoint& _pos){ | ||
x = _pos.x; | ||
y = _pos.y; | ||
} | ||
|
||
void goTo(const ofPoint& target, float k = 0.1f, float damp = 0.9f){ | ||
accel = (target - *this)*k; | ||
vel += accel; | ||
vel *= damp; | ||
*this += vel; | ||
} | ||
|
||
void update(const ofPoint& _force, float damp = 0.9f){ | ||
vel += _force; | ||
vel *= damp; | ||
*this += vel; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "ofMain.h" | ||
#include "testApp.h" | ||
#include "ofAppGlutWindow.h" | ||
|
||
//======================================================================== | ||
int main( ){ | ||
|
||
ofAppGlutWindow window; | ||
ofSetupOpenGL(&window, 1280,720, OF_WINDOW); // <-------- setup the GL context | ||
|
||
// this kicks off the running of my app | ||
// can be OF_WINDOW or OF_FULLSCREEN | ||
// pass in width and height too: | ||
ofRunApp( new testApp()); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#include "testApp.h" | ||
|
||
float startTime = 0.02; | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::setup() { | ||
ofSetFrameRate(60); | ||
ofSetVerticalSync(true); | ||
|
||
rotate = 0; | ||
|
||
bvh[0].load("bvhfiles/kashiyuka.bvh"); | ||
bvh[1].load("bvhfiles/nocchi.bvh"); | ||
bvh[2].load("bvhfiles/aachan.bvh"); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
bvh[i].play(); | ||
} | ||
|
||
track.loadSound("Perfume_globalsite_sound.wav"); | ||
track.play(); | ||
track.setLoop(true); | ||
|
||
camera.setFov(30); | ||
camera.setDistance(700); | ||
|
||
// MarchingCube init | ||
ofPoint iniPos(0,0,0); | ||
ofPoint gridSize(550, 550, 550); | ||
int gridResX = 60; | ||
int gridResY = 60; | ||
int gridResZ = 60; | ||
marchingCubes.init(iniPos, gridSize, gridResX, gridResY, gridResZ); | ||
|
||
// Metaball init | ||
int metaballNum = bvh[0].getNumJoints() + bvh[1].getNumJoints() + bvh[2].getNumJoints(); | ||
metaBalls.resize(metaballNum); | ||
|
||
int n = 0; | ||
for (int i = 0; i < 3; i++){ | ||
for (int j = 0; j < bvh[i].getNumJoints(); j++) { | ||
const ofxBvhJoint *o = bvh[i].getJoint(j); | ||
if (o->isSite()) { | ||
metaBalls[n].init(o->getPosition()); | ||
metaBalls[n].size = 1.4; | ||
} | ||
n++; | ||
} | ||
} | ||
|
||
light.enable(); | ||
light.setAmbientColor(ofFloatColor(0.1, 0.3, 0.8, 1.0)); | ||
light.setDiffuseColor(ofFloatColor(0.7, 0.7, 0.7)); | ||
light.setSpecularColor(ofFloatColor(1.0, 0.5, 0.0)); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::update(){ | ||
float t = (track.getPosition() * 64.28); | ||
t = t / bvh[0].getDuration(); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
bvh[i].setPosition(t); | ||
bvh[i].update(); | ||
} | ||
|
||
marchingCubes.resetIsoValues(); | ||
|
||
int n = 0; | ||
for (int i = 0; i < 3; i++){ | ||
for (int j = 0; j < bvh[i].getNumJoints(); j++) { | ||
const ofxBvhJoint *o = bvh[i].getJoint(j); | ||
if (o->isSite()) { | ||
if (t > startTime) { | ||
metaBalls[n].goTo(o->getPosition(), 0.3, 0.94); | ||
marchingCubes.addMetaBall(metaBalls[n], metaBalls[n].size); | ||
} else { | ||
metaBalls[n].goTo(o->getPosition(), 1.0, 0.1); | ||
} | ||
} | ||
n++; | ||
} | ||
} | ||
|
||
marchingCubes.update(0.17, true); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::draw(){ | ||
ofBackgroundHex(0x222222); | ||
|
||
camera.begin(); | ||
ofPushMatrix(); | ||
{ | ||
ofTranslate(0, -80); | ||
ofRotate(5, 1, 0, 0); | ||
ofScale(1, 1, 1); | ||
|
||
// draw MarchingCubes | ||
vector<ofPoint>& vertices = marchingCubes.getVertices(); | ||
vector<ofPoint>& normals = marchingCubes.getNormals(); | ||
int numVertices = vertices.size(); | ||
|
||
glEnable(GL_DEPTH_TEST); | ||
glColor3f(1.0f, 1.0f, 1.0f); | ||
glBegin(GL_TRIANGLES); | ||
|
||
for(int i=0; i<numVertices; i++){ | ||
glNormal3f(normals[i].x, normals[i].y, normals[i].z); | ||
glVertex3f(vertices[i].x, vertices[i].y, vertices[i].z); | ||
} | ||
|
||
glEnd(); | ||
glDisable(GL_DEPTH_TEST); | ||
|
||
} | ||
|
||
ofPopMatrix(); | ||
camera.end(); | ||
|
||
} | ||
|
||
void testApp::exit(){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::keyPressed(int key){ | ||
if (key == 'f') { | ||
ofToggleFullscreen(); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::keyReleased(int key){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseMoved(int x, int y ){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseDragged(int x, int y, int button){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mousePressed(int x, int y, int button){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseReleased(int x, int y, int button){ | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::windowResized(int w, int h){ | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::gotMessage(ofMessage msg){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::dragEvent(ofDragInfo dragInfo){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "ofMain.h" | ||
|
||
#include "ofxBvh.h" | ||
#include "ofxSTL.h" | ||
#include "ofxMarchingCubes.h" | ||
#include "MetaBall.h" | ||
|
||
class testApp : public ofBaseApp{ | ||
|
||
public: | ||
void setup(); | ||
void update(); | ||
void draw(); | ||
void exit(); | ||
|
||
void keyPressed (int key); | ||
void keyReleased(int key); | ||
void mouseMoved(int x, int y ); | ||
void mouseDragged(int x, int y, int button); | ||
void mousePressed(int x, int y, int button); | ||
void mouseReleased(int x, int y, int button); | ||
void windowResized(int w, int h); | ||
void dragEvent(ofDragInfo dragInfo); | ||
void gotMessage(ofMessage msg); | ||
|
||
ofSoundPlayer track; | ||
ofxBvh bvh[3]; | ||
|
||
float rotate; | ||
float play_rate, play_rate_t; | ||
|
||
ofEasyCam camera; | ||
ofImage background; | ||
|
||
ofxMarchingCubes marchingCubes; | ||
vector<MetaBall> metaBalls; | ||
|
||
float threshold; | ||
ofLight light; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.svn | ||
.hg | ||
.cvs | ||
|
||
# osx | ||
*.app | ||
*.mode1v3 | ||
*.pbxuser | ||
.DS_Store | ||
build | ||
xcuserdata | ||
DerivedData | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2012 Atsushi Tadokoro (http://yoppa.org/) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.