package com.haxademic.demo.render.joons;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.constants.AppSettings;
import com.haxademic.core.draw.context.DrawUtil;
import com.haxademic.core.draw.shapes.PShapeUtil;
import com.haxademic.core.file.FileUtil;
import com.haxademic.core.render.JoonsWrapper;

import processing.core.PShape;

public class JoonsPShapeRender
extends PAppletHax {
	public static void main(String args[]) { PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }

	protected PShape obj;
	protected float objHeight;
	
	protected void overridePropsFile() {
		p.appConfig.setProperty( AppSettings.SUNFLOW, true );
		p.appConfig.setProperty( AppSettings.SUNFLOW_ACTIVE, false );
		p.appConfig.setProperty( AppSettings.SUNFLOW_QUALITY, AppSettings.SUNFLOW_QUALITY_HIGH );

		p.appConfig.setProperty( AppSettings.WIDTH, 960 );
		p.appConfig.setProperty( AppSettings.HEIGHT, 720 );
		p.appConfig.setProperty( AppSettings.RENDERING_IMAGE_SEQUENCE, true );
		p.appConfig.setProperty( AppSettings.RENDERING_IMAGE_SEQUENCE_START_FRAME, 2 );
		p.appConfig.setProperty( AppSettings.RENDERING_IMAGE_SEQUENCE_STOP_FRAME, 4 );
	}

	public void setup() {
		super.setup();
		
		// load & normalize shape
		obj = p.loadShape( FileUtil.getFile("models/skull-realistic.obj"));	
		obj = p.loadShape( FileUtil.getFile("models/poly-hole-penta.obj"));	
		PShapeUtil.centerSvg(obj);
		PShapeUtil.scaleObjToExtentVerticesAdjust(obj, p.height * 0.4f);
		objHeight = PShapeUtil.getObjHeight(obj);
	}


	public void drawApp() {
		if(joons == null) {
			p.background(0);
			p.lights();
		}
//		joons.jr.background(JoonsWrapper.BACKGROUND_GI);
		joons.jr.background(JoonsWrapper.BACKGROUND_AO);
		p.translate(0, 0, -width);

		// draw environment
		p.pushMatrix();
		setUpRoom();
		p.popMatrix();
		
		// draw shape
		p.pushMatrix();
		p.rotateZ(P.PI);
		joons.jr.fill(JoonsWrapper.MATERIAL_PHONG, 205, 150, 205);		p.fill( 205, 150, 205 );
		PShapeUtil.drawTrianglesJoons(p, obj, 1);
		p.popMatrix();

		// draw box
		p.pushMatrix();
//		joons.jr.fill(JoonsWrapper.MATERIAL_LIGHT, 5, 5, 5);		p.fill( 255, 255, 255 );
		joons.jr.fill(JoonsWrapper.MATERIAL_AMBIENT_OCCLUSION, 60, 60, 60, 0, 0, 0,   50, 16);
		p.rotateY(1);
		p.rotateZ(1);
		p.sphere(200);
		p.popMatrix();
		
		// draw floor
		p.pushMatrix();
		DrawUtil.setDrawCenter(p);
		p.translate(0, objHeight/2);
		joons.jr.fill(JoonsWrapper.MATERIAL_PHONG, 10, 90, 10);		p.fill( 10, 90, 10 );
		p.box(p.height * 3, 2, p.height * 3);
		p.popMatrix();
	}

	protected void setUpRoom() {
		pushMatrix();
		translate(0, 0, 0);
		float radiance = 10;
		int samples = 16;
		joons.jr.background(JoonsWrapper.CORNELL_BOX, 
				4000, 3000, 5000,						// width, height, depth
				radiance, radiance, radiance, samples,  // radiance rgb & samples
				40, 40, 40, 							// left rgb
				40, 40, 40, 							// right rgb
				0, 0, 0,	 							// back rgb
				60, 60, 60, 							// top rgb
				60, 60, 60  							// bottom rgb
		); 
		popMatrix();		
	}
	
}
@@ -602,18 +602,49 @@
 Height;%0A
+%09protected float frames = 200;%0A
 %09%0A
-
 %09protect
@@ -1058,19 +1058,20 @@
 QUENCE, 
-tru
+fals
 e );%0A%09%09p
@@ -1144,17 +1144,17 @@
 _FRAME, 
-2
+3
  );%0A%09%09p.
@@ -1225,17 +1225,22 @@
 _FRAME, 
-4
+3 + 20
  );%0A%09%7D%0A%0A
@@ -1631,21 +1631,74 @@
 %09if(
-joons == null
+p.appConfig.getBoolean(AppSettings.SUNFLOW_ACTIVE, false) == false
 ) %7B%0A
@@ -1732,16 +1732,33 @@
 ghts();%0A
+%09%09%09p.noStroke();%0A
 %09%09%7D%0A//%09%09
@@ -1885,16 +1885,86 @@
 -width);
+%0A%09%09%0A%09%09// progress%0A%09%09float progress = (p.frameCount %25 frames) / frames;
 %0A%0A%09%09// d
@@ -2081,24 +2081,58 @@
 ateZ(P.PI);%0A
+%09%09p.rotateY(progress * P.TWO_PI);%0A
 %09%09joons.jr.f
@@ -2278,19 +2278,22 @@
 // draw 
-box
+sphere
 %0A%09%09p.pus
@@ -2443,26 +2443,61 @@
 LUSION, 
-60, 60, 60
+10, 10, 30 + 20f * P.sin(progress * P.TWO_PI)
 , 0, 0, 
@@ -2554,17 +2554,17 @@
 sphere(2
-0
+1
 0);%0A%09%09p.
@@ -2718,25 +2718,25 @@
 _PHONG, 10, 
-9
+1
 0, 10);%09%09p.f
@@ -2744,17 +2744,17 @@
 ll( 10, 
-9
+1
 0, 10 );

Improve Joons demo