Skip to content

Commit

Permalink
rendering and comp system
Browse files Browse the repository at this point in the history
  • Loading branch information
obviousjim committed May 6, 2012
1 parent 1f3df6c commit c2a73c9
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 67 deletions.
1 change: 1 addition & 0 deletions CloudsChaos/src/CloudInterludeForce.h
Expand Up @@ -13,6 +13,7 @@

class CloudInterludeForce {
public:
virtual void update() = 0;
virtual void applyForce(vector<CloudInterludeParticle>& particles) = 0;
};

Expand Down
2 changes: 2 additions & 0 deletions CloudsChaos/src/CloudInterludeForceDrag.h
Expand Up @@ -16,6 +16,8 @@ class CloudInterludeForceDrag : public CloudInterludeForce {
dragForce = 1.0;
}

void update(){};

void applyForce(vector<CloudInterludeParticle>& particles){
//float oneMinusDrag = (1.0 - dragForce);
for(int i = 0; i < particles.size(); i++){
Expand Down
2 changes: 2 additions & 0 deletions CloudsChaos/src/CloudInterludeForceMeshAttractor.h
Expand Up @@ -16,6 +16,8 @@ class CloudInterludeForceMeshAttractor : public CloudInterludeForce {

}

void update(){}

void applyForce(vector<CloudInterludeParticle>& particles){

int step = 200;
Expand Down
8 changes: 6 additions & 2 deletions CloudsChaos/src/CloudInterludeForcePerlin.h
Expand Up @@ -12,6 +12,7 @@
#include "CloudInterludeForce.h"
class CloudInterludeForcePerlin : public CloudInterludeForce {
public:

float amplitude;
float density;
float speed;
Expand All @@ -24,9 +25,12 @@ class CloudInterludeForcePerlin : public CloudInterludeForce {
currentOffset = 0;
}

void applyForce(vector<CloudInterludeParticle>& particles){
void update(){
currentOffset += speed;
currentOffset = 0;
}

void applyForce(vector<CloudInterludeParticle>& particles){
//currentOffset = 0;
for(int i = 0; i < particles.size(); i++){
ofVec3f& pos = particles[i].position;
// particles[i].force += ofVec3f(ofSignedNoise(pos.x/density, pos.y/density, pos.z/density, currentOffset)*amplitude,
Expand Down
168 changes: 108 additions & 60 deletions CloudsChaos/src/testApp.cpp
Expand Up @@ -8,10 +8,11 @@ void testApp::setup(){

ofToggleFullscreen();

renderTarget.allocate(1920, 1080, GL_RGBA, 4);
renderTarget.allocate(1920, 1080, GL_RGB, 4);

renderer.setSimplification(2);
//renderer.forceUndistortOff = true;
renderer.forceUndistortOff = true;


cam.setup();
cam.usemouse = true;
Expand All @@ -25,24 +26,31 @@ void testApp::setup(){
cam.rollSpeed = 1;
cam.loadCameraPosition();

currentSaveFolder = "EXPORT_" + ofToString(ofGetMonth()) + "_" + ofToString(ofGetDay()) + "_" + ofToString(ofGetHours()) + ofToString(ofGetMinutes());
savingImage.allocate(1920, 1080, OF_IMAGE_COLOR);
createdFolder = false;

track.setCamera(cam);
track.setXMLFileName("cameraMoves.xml");
timeline.setup();
timeline.setMovePlayheadOnDrag(false);
timeline.setDurationInFrames(500);
timeline.setOffset(ofVec2f(0,0));

useShader = false;


int absoluteMaxParticles = 40000;
depthImages.setup();
timeline.setPageName("Source");
timeline.addElement("Depth", &depthImages);
timeline.addElement("Track", &track);

timeline.addPage("Rendering");
timeline.addKeyframes("Simplify", "zthreshold.xml", ofRange(0, 8 ), 2);
timeline.addKeyframes("Z Threshold", "zthreshold.xml", ofRange(0, sqrtf(5000) ), sqrtf(5000));
timeline.addKeyframes("Edge Snip", "edgesnip.xml", ofRange(0, sqrtf(2000) ), sqrtf(2000));


timeline.addPage("Particles");
timeline.addKeyframes("Max Particles", "maxParticles.xml", ofRange(10, absoluteMaxParticles) );
timeline.addKeyframes("Birthrate", "particleBirthrate.xml", ofRange(.001, .01) );
timeline.addKeyframes("Max Particles", "maxParticles.xml", ofRange(0, absoluteMaxParticles) );
timeline.addKeyframes("Birthrate", "particleBirthrate.xml", ofRange(.000, .01) );
timeline.addKeyframes("Lifespan", "particleLifespan.xml", ofRange(2, 300) );
timeline.addKeyframes("Lifespan Variance", "particleLifespanVariance.xml", ofRange(0, 100) );
timeline.addKeyframes("Drag Force", "particleDragFroce.xml", ofRange(0, 1.0), 0);
Expand All @@ -54,7 +62,7 @@ void testApp::setup(){
timeline.addKeyframes("Max Point Size", "dofMaxPoint.xml", ofRange(10, 45));

timeline.addPage("Perlin");
timeline.addKeyframes("Perlin Amplitude", "perlinAmplitude.xml", ofRange(0, sqrtf(200)) );
timeline.addKeyframes("Perlin Amplitude", "perlinAmplitude.xml", ofRange(0, sqrtf(20)) );
timeline.addKeyframes("Perlin Density", "perlinDensity.xml", ofRange(0, sqrtf(2000)));
timeline.addKeyframes("Perlin Speed", "perlinSpeed.xml", ofRange(0, sqrtf(5)), 0);

Expand All @@ -63,12 +71,21 @@ void testApp::setup(){
timeline.addKeyframes("Min Radius", "meshMinRadius.xml", ofRange(0, 6000));
timeline.setCurrentPage(0);

// timeline.addPage("Luminosity");
// timeline.addKeyframes("Lumin Mid", "Lumin Mid", <#ofRange valueRange#>)

panel.setup("Settings", "settings.xml");
panel.add(setCompDirectory.setup("load comp"));
panel.add(renderOutput.setup("render", false));
panel.add(lockToTrackToggle.setup("lock to track",false));
panel.add(resetCamera.setup("reset cam", false));
panel.add(useShaderToggle.setup("use shader",true));
panel.add(reloadShaders.setup("reload shader", false));
panel.add(clear.setup("clear", false));

renderOutput = false; // force false
framesSaved = 0;
ofxXmlSettings defaults;
defaults.loadFile("defaults.xml");
string defaultTake = defaults.getValue("take", "");
string defaultComp = defaults.getValue("comp", "");
if(defaultTake != "" && take.loadFromFolder(defaultTake)){

renderer.setup(take.calibrationDirectory);
Expand All @@ -78,23 +95,19 @@ void testApp::setup(){
timeline.setDurationInFrames(depthImages.videoThumbs.size());

// alignment.loadPairingFile(take.pairingsFile);

// movie.loadMovie(take.lowResVideoPath);
// movie.setUseTexture(false);
// movie.play();
// movie.setSpeed(0);

// playerElement.setVideoPlayer(movie, take.videoThumbsPath);
// timeline.addElement("Video", &playerElement);
// timeline.addElement("Video", &playerElement);
// timeline.setDurationInFrames(movie.getDuration());
}

for(int i = 0; i < 50; i++){
ofNode n;
n.setPosition(ofRandom(-200,200),
ofRandom(-200,200),
ofRandom(-200,200) );
debugNodes.push_back( n );
if(defaultComp != ""){
cout << "loading default comp" << defaultComp << endl;
timeline.loadElementsFromFolder(defaultComp);
currentSaveFolder = defaultComp + "EXPORTS";
}

//setup forces
Expand All @@ -111,7 +124,7 @@ void testApp::setup(){
emmiters.push_back(g);
}

for(int i = 0; i < absoluteMaxParticles; i++){
for(int i = 0; i < absoluteMaxParticles*1.5; i++){
mesh.addVertex(ofVec3f(0,0,0));
mesh.addColor(ofFloatColor(1.0,1.0,1.0,1.0));
}
Expand All @@ -126,9 +139,50 @@ void testApp::update(){
return;
}

if(reloadShaders){
loadShaders();
}
if(saveCameraPoint){
track.sample();
}

if(clear){
for(int i = 0; i < emmiters.size(); i++){
emmiters[i].particles.clear();
}
}

if(setCompDirectory){
ofFileDialogResult r = ofSystemLoadDialog("Select Comp", true);
if(r.bSuccess){

timeline.loadElementsFromFolder(r.getPath() + "/");
currentSaveFolder = r.getPath() + "/EXPORTS";
ofDirectory(currentSaveFolder).create(true);

ofxXmlSettings defaults;
defaults.loadFile("defaults.xml");
defaults.setValue("comp", r.getPath() + "/");
defaults.saveFile();
}
}
track.lockCameraToTrack = lockToTrackToggle;
if(lockToTrackToggle){
cam.targetNode.setPosition(cam.getPosition());
cam.targetNode.setOrientation(cam.getOrientationQuat());
cam.rotationX = cam.targetXRot = -cam.getHeading();
cam.rotationY = cam.targetYRot = -cam.getPitch();
// cam.rotationZ = -cam.getRoll();
}
if(resetCamera){
cam.reset();
}

//VIEW
cam.applyRotation = cam.applyTranslation = fboRect.inside(ofGetMouseX(),ofGetMouseY());
fboRect = ofRectangle(timeline.getDrawRect().x, timeline.getDrawRect().height, 1920/2, 1080/2);
float fboHeight = ofGetHeight() - timeline.getDrawRect().height - 28;
float fboWidth = 1920./1080 * fboHeight;
fboRect = ofRectangle(timeline.getDrawRect().x, timeline.getDrawRect().height + 28, fboWidth, fboHeight);
cam.applyRotation = cam.applyTranslation = fboRect.inside(ofGetMouseX(),ofGetMouseY()) && !lockToTrackToggle;

dragForce->dragForce = powf( timeline.getKeyframeValue("Drag Force"), 2.0);

Expand All @@ -138,7 +192,11 @@ void testApp::update(){

meshForce->minRadius = timeline.getKeyframeValue("Min Radius");
meshForce->attractScale = timeline.getKeyframeValue("Mesh Attract");


dragForce->update();
perlinForce->update();
meshForce->update();

//GENERATOR
float birthRate = timeline.getKeyframeValue("Birthrate");
float lifeSpan = timeline.getKeyframeValue("Lifespan");
Expand Down Expand Up @@ -211,56 +269,38 @@ void testApp::draw(){
cam.begin(ofRectangle(0,0,1920,1080));
// ofDrawGrid();

if(depthImages.isLoaded()){
ofPushStyle();
ofSetColor(255);
// renderer.drawWireFrame(false);
ofPopStyle();
//for(int i = 0; i < debugNodes.size(); i++) debugNodes[i].draw();
}
ofPushStyle();
ofSetColor(255);
// renderer.drawWireFrame(false);
ofPopStyle();

//RENDERER
//glPointSize(4);
ofPushStyle();
glPushMatrix();
glScalef(1,-1,1);
if(useShader){
if(useShaderToggle){
pointCloudDOF.begin();
pointCloudDOF.setUniform1f("minSize", timeline.getKeyframeValue("Min Point Size"));
pointCloudDOF.setUniform1f("maxSize", timeline.getKeyframeValue("Max Point Size"));
pointCloudDOF.setUniform1f("focalRange", timeline.getKeyframeValue("Focal Range"));
pointCloudDOF.setUniform1f("focalDistance", timeline.getKeyframeValue("Focal Distance"));
}
else{
glPointSize(4);
glPointSize(timeline.getKeyframeValue("Min Point Size"));
}

ofEnableBlendMode(OF_BLENDMODE_ADD);
glEnable(GL_POINT_SMOOTH); // makes circular points
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); // allows per-point size
mesh.drawVertices();
if(useShader){
if(useShaderToggle){
pointCloudDOF.end();
}
glPopMatrix();
ofPopStyle();

//debugDrawOrigins();

/*
glBegin(GL_POINTS);
glPointSize(4);
glColor3f(1.0, 0, 0);
int totalValidVerts = 0;
for(int i = 0; i < renderer.getMesh().getVertices().size(); i++){
if(renderer.isVertexValid(i) ){
totalValidVerts++;
ofVec3f vert = renderer.getMesh().getVertex( renderer.vertexIndex(i) );
glVertex3f(vert.x, vert.y, vert.z);
}
}
glEnd();
cout << "valid verts " << totalValidVerts << endl;
*/

cam.end();

Expand All @@ -272,10 +312,19 @@ void testApp::draw(){
ofPopStyle();

renderTarget.getTextureReference().draw(fboRect);
if(renderOutput){
renderTarget.getTextureReference().readToPixels(savingImage.getPixelsRef());
char filename[512];
sprintf(filename, "%s/save_%05d_%05d.png", currentSaveFolder.c_str(), framesSaved, timeline.getCurrentFrame());
savingImage.saveImage(filename);
framesSaved++;
}

ofDrawBitmapString("totalParticles " + ofToString(totalParticles ), fboRect.x+fboRect.width + 10, fboRect.y + 15);

ofDrawBitmapString("Saving to " + currentSaveFolder, 10, fboRect.y - 15);
timeline.draw();
panel.setPosition(ofPoint(fboRect.x+fboRect.width + 10, fboRect.y + 32));
panel.draw();
}

void testApp::debugDrawOrigins(){
Expand Down Expand Up @@ -345,21 +394,20 @@ void testApp::keyPressed(int key){
}

if(key == 'R'){
cam.reset();

}

if(key == 'K'){
for(int i = 0; i < emmiters.size(); i++){
emmiters[i].particles.clear();
}
if(key == 'C'){
}

if(key == 'L'){
loadShaders();
//loadShaders();
//lockToTrackToggle != lockToTrackToggle;
lockToTrackToggle = !lockToTrackToggle;
}

if(key == 'N'){
useShader = !useShader;
if(key == 'T'){
track.sample();
}
}

Expand Down

0 comments on commit c2a73c9

Please sign in to comment.