Sunflow works irregularly after first frame processing 1.5.1
in
Contributed Library Questions
•
7 months ago
Hi,
What is going on with sunflow render after first frame?
Firstly, I have to say that everything with the library is ok, and everything is working.
Smth is not good with the sunflow camera.
After the first frame, second frame is zoomed in. When I tried to zoom out processing camera, I got the same results.
The scene is just simple rotating camera.
Maybe there is a problem that the camera is being rotated every frame?
- import java.awt.Color;
- import sunflowapiapi.P5SunflowAPIAPI;
- import org.sunflow.math.Point3;
- import org.sunflow.math.Vector3;
- import punktiert.physics.*;
- import punktiert.math.Vec;
- import processing.opengl.*;
- import processing.dxf.*;
- import peasy.PeasyCam;
- PeasyCam cam;
- float distance = 800;
- VPhysics physics;
- VPhysics physicsDrive;
- //object for loading Pictures
- PImage map;
- //declaring lists for storing specific elements
- ArrayList<Point> points;
- ArrayList<ArrayList> shapes;
- ArrayList<Nail> nails;
- ArrayList<Point> movers;
- ArrayList<BAttraction> attrs;
- ArrayList<ArrayList> meshList;
- float angle = 0;
- //strength of imported attractors
- float attrStrength = 0.005;
- //use underlying map
- boolean useMap =false;
- int sceneWidth = (int)(1280*1.5);
- int sceneHeight = (int)(720*1.5);
- P5SunflowAPIAPI sunflow ;
- ////////////////////////////////////////////////////////////
- public void setup() {
- size(sceneWidth, sceneHeight, "sunflowapiapi.P5SunflowAPIAPI");//"sunflowapiapi.P5SunflowAPIAPI"
- sunflow = (P5SunflowAPIAPI) g;
- sunflow.setAmbientOcclusionShader();
- smooth();
- //set up camera (PApplet, distance)
- perspective(PI/3.0, width/height, 1, 100000);
- // inizialize physics engine
- physics = new VPhysics(0);
- physicsDrive = new VPhysics(500);
- physicsDrive.setfriction(.1);
- //initialize lists
- attrs = new ArrayList<BAttraction>();
- nails = new ArrayList<Nail>();
- movers = new ArrayList<Point>();
- points = new ArrayList<Point>();
- shapes = new ArrayList<ArrayList>();
- //import objects from text-files
- importMovers("/data/fromRhino/movers.txt");
- importNails("/data/fromRhino/nails.txt");
- importShapes("/data/fromRhino/shapes.txt");
- importSprings("/data/fromRhino/springsInternal.txt");
- importSprings("/data/fromRhino/springsExternal.txt");
- meshList = importMesh("/data/fromRhino/mesh.txt");
- BAttraction attr = new BAttraction(new Vec(0, 0, 200), 800, .1);
- physicsDrive.addBehavior(attr);
- sunflow = (P5SunflowAPIAPI) g;
- sunflow.setWidth(sceneWidth);
- sunflow.setHeight(sceneHeight);
- }
- ////////////////////////////////////////////////////////////
- public void draw() {
- background(225);
- lights();
- float x = cos(0.025*frameCount/10) * distance;
- float y = -distance;
- float z = sin(0.025*frameCount/10) * distance;
- camera(x, y, z, -110, 0, 0, 0, 1, 0);
- rotateX(PI/2);
- fill(220);
- ////////////////////////////////////////////////////////////
- //update physics engine/ simulation
- if (pause) {
- physics.update();
- physicsDrive.update();
- }
- ////////////////////////////////////////////////////////////
- if (export == true) beginRaw(DXF, "/export/"+day()+hour()+minute()+"_#####.dxf");
- ////////////////////////////////////////////////////////////
- fill(220);
- noStroke();
- if (!showDelaunay) {
- drawShapes();
- }
- else {
- drawNet();
- }
- ////////////////////////////////////////////////////////////
- if (showNails) {
- for (Nail n : nails) {
- n.display();
- }
- }
- ////////////////////////////////////////////////////////////
- if (showAttrs) {
- stroke(200, 50);
- for (BAttraction a : attrs) {
- strokeWeight(a.getRadius()*2);
- Vec pos = a.getAttractor();
- point(pos.x, pos.y, pos.z);
- }
- }
- ////////////////////////////////////////////////////////////
- if (showSprings) {
- stroke(100);
- strokeWeight(1);
- for (VSpring s : physics.springs) {
- line(s.a.x, s.a.y, s.a.z, s.b.x, s.b.y, s.b.z);
- }
- }
- for (int i =0;i<movers.size();i++) {
- Point m = (Point) movers.get(i);
- VParticle nail = (VParticle) physicsDrive.particles.get(i);
- Vec vel = m.getVelocity();
- Vec newPos = nail.copy();
- m.set(newPos);
- m.setPreviousPosition(m.sub(0, 0, 250));
- m.lock();
- }
- ////////////////////////////////////////////////////////////
- if (showMovers) {
- for (VParticle m : physicsDrive.particles) {
- // strokeWeight(m.getRadius()*.5);
- fill(0, 200, 0, 100);
- //point(m.x, m.y, m.z);
- ellipse(m.x, m.y, m.getRadius()*2, m.getRadius()*2);
- }
- strokeWeight(1);
- for (VSpring s : physicsDrive.springs) {
- line(s.a.x, s.a.y, s.a.z, s.b.x, s.b.y, s.b.z);
- }
- }
- ////////////////////////////////////////////////////////////
- if (export == true) {
- endRaw();
- export = false;
- println("savedDXF: "+day()+hour()+minute()+"_#####.dxf");
- }
- fill(100);
- fill(100);
- beginShape();
- vertex(-10000000, -10000000, -50);
- vertex(10000000, -1000000, -50);
- vertex(10000000, 10000000, -50);
- vertex(-10000000, 10000000, -50);
- endShape(CLOSE);
- fill(220);
- ////////////////////////////////////////////////////////////
- //with this you can record every frame a pic and combine it later with tools/moviemaker
- //saveFrame("pics01/pics01_#####.png");
- if (frameCount%1==0) {
- sunflow.setPathTracingGIEngine(16);
- sunflow.render(false, sketchPath + "/"+frameCount+".png");
- }
- }
1