Skip to content

Commit

Permalink
Shape has gone!
Browse files Browse the repository at this point in the history
  • Loading branch information
nakednous committed Jan 14, 2019
1 parent 648fb5d commit 377d7b9
Show file tree
Hide file tree
Showing 30 changed files with 269 additions and 378 deletions.
2 changes: 1 addition & 1 deletion resources/code/ExampleTaglet.java
Expand Up @@ -191,7 +191,7 @@ String createHTML(String theString) {
"dd.style.display = toOpen? 'block':''; dt.getElementsByTagName('span')[0].innerHTML = toOpen? '-':'+' ; }\n" +
"-->\n</script>";

return dd+"\n<div id=\"test\" class=\"toggleList\">" +
return dd+"\n<div colorID=\"test\" class=\"toggleList\">" +
"<dl><dt onclick=\"toggle(this);\"><span>+</span>Example</dt>" +
"<dd><pre>"+theString+"</pre>" +
"</dd></dl></div>";
Expand Down
38 changes: 30 additions & 8 deletions src/frames/core/Frame.java
Expand Up @@ -475,13 +475,17 @@ public void reset() {
setScaling(1);
}

// id
// colorID

public int id() {
return _id;
}

/**
* Uniquely identifies the frame. Also the color to be used for picking with a color buffer.
* See: http://stackoverflow.com/questions/2262100/rgb-int-to-rgb-python
*/
public int id() {
public int colorID() {
return (255 << 24) | ((_id & 255) << 16) | (((_id >> 8) & 255) << 8) | (_id >> 16) & 255;
}

Expand Down Expand Up @@ -2331,7 +2335,7 @@ public Highlighting highlighting() {
* @see #backShape(Object)
* @see #shape(Object)
*/
protected void graphics(Object context) {
public void graphics(Object context) {
}

/**
Expand All @@ -2341,7 +2345,7 @@ protected void graphics(Object context) {
* @see #graphics(Object)
* @see #shape(Object)
*/
protected void frontGraphics(Object context) {
public void frontGraphics(Object context) {
}

/**
Expand All @@ -2351,7 +2355,7 @@ protected void frontGraphics(Object context) {
* @see #graphics(Object)
* @see #shape(Object)
*/
protected void backGraphics(Object context) {
public void backGraphics(Object context) {
}

/**
Expand Down Expand Up @@ -2388,6 +2392,14 @@ public void backShape(Object shape) {
_backShape = shape;
}

public Object frontShape() {
return _frontShape;
}

public Object backShape() {
return _backShape;
}

// Java version of the rendering methods

/**
Expand All @@ -2400,7 +2412,7 @@ public void backShape(Object shape) {
* @see #backGraphics(processing.core.PGraphics)
* @see #shape(processing.core.PShape)
*/
protected void graphics(processing.core.PGraphics pGraphics) {
public void graphics(processing.core.PGraphics pGraphics) {
}

/**
Expand All @@ -2410,7 +2422,7 @@ protected void graphics(processing.core.PGraphics pGraphics) {
* @see #graphics(processing.core.PGraphics)
* @see #shape(processing.core.PShape)
*/
protected void frontGraphics(processing.core.PGraphics pGraphics) {
public void frontGraphics(processing.core.PGraphics pGraphics) {
}

/**
Expand All @@ -2420,7 +2432,7 @@ protected void frontGraphics(processing.core.PGraphics pGraphics) {
* @see #graphics(processing.core.PGraphics)
* @see #shape(processing.core.PShape)
*/
protected void backGraphics(processing.core.PGraphics pGraphics) {
public void backGraphics(processing.core.PGraphics pGraphics) {
}

/**
Expand Down Expand Up @@ -2456,4 +2468,14 @@ public void frontShape(processing.core.PShape pshape) {
public void backShape(processing.core.PShape pshape) {
_backShape = pshape;
}

/*
public processing.core.PShape frontShape() {
return (processing.core.PShape)_frontShape;
}
public processing.core.PShape backShape() {
return (processing.core.PShape)_backShape;
}
*/
}
15 changes: 10 additions & 5 deletions src/frames/core/Graph.java
Expand Up @@ -2824,17 +2824,22 @@ protected void _draw(MatrixHandler matrixHandler, Object context, Frame frame) {
matrixHandler.pushModelView();
_applyTransformation(matrixHandler, frame, is2D());
_track(frame);
_render(context, frame);
if (context == backBuffer())
_drawBackBuffer(context, frame);
else
_draw(context, frame);
if (!frame.isCulled())
for (Frame child : frame.children())
_draw(matrixHandler, context, child);
matrixHandler.popModelView();
}

protected void _render(Object context, Frame frame) {
// TODO discard condition & focus on testing culling on the back buffer
//if (context != backBuffer() || frame instanceof Shape)
frame.draw(context);
protected void _draw(Object context, Frame frame) {

}

protected void _drawBackBuffer(Object context, Frame frame) {

}

/**
Expand Down
137 changes: 108 additions & 29 deletions src/frames/processing/Scene.java
Expand Up @@ -64,33 +64,6 @@
* }
* </pre>
* In this case, the scene {@link #frontBuffer()} corresponds to the {@code canvas}.
* <h2>Shapes</h2>
* A {@link Shape} is a {@link Frame} specialization that can be set from a
* retained-mode rendering Processing {@code PShape} or from an immediate-mode
* rendering Processing procedure. Shapes can be picked precisely using their projection
* onto the screen, see {@link Shape#setPrecision(Frame.Precision)}. Use
* {@link #render()} to render all scene shapes or {@link Shape#draw()} to
* render a specific one instead.
* <h3>Retained-mode shapes</h3>
* To set a retained-mode shape use {@code Shape shape = new Shape(Scene scene,
* PShape shape)} or {@code Shape shape = new Shape(Scene scene)} and then call
* {@link Shape#graphics(PGraphics)}.
* <h3>Immediate-mode shapes</h3>
* To set an immediate-mode shape use code such as the following:
* <pre>
* {@code
* ...
* Shape shape;
* void setup() {
* ...
* shape = new Shape(scene) {
* public void set(PGraphics canvas) {
* //immediate-mode rendering procedure
* }
* };
* }
* }
* </pre>
* <h1>Drawing functionality</h1>
* There are several static drawing functions that complements those already provided
* by Processing, such as: {@link #drawCylinder(PGraphics, int, float, float)},
Expand All @@ -103,7 +76,8 @@
* static ones), such as {@link #beginHUD(PGraphics)},
* {@link #endHUD(PGraphics)}, {@link #drawAxes(PGraphics, float)},
* {@link #drawCross(PGraphics, float, float, float)} and {@link #drawGrid(PGraphics)}
* among others, can be used to set a {@link Shape} (see {@link Shape#graphics(PGraphics)}).
* among others, can be used to set a {@link Frame#shape(PShape)} (see
* also {@link Frame#graphics(PGraphics)}).
* <p>
* Another scene's eye (different than this one) can be drawn with
* {@link #drawFrustum(Graph)}. Typical usage include interactive minimaps and
Expand Down Expand Up @@ -1002,10 +976,115 @@ protected boolean _tracks(float x, float y, Frame frame) {
int index = (int) y * width() + (int) x;
if (backBuffer().pixels != null)
if ((0 <= index) && (index < backBuffer().pixels.length))
return backBuffer().pixels[index] == frame.id();
return backBuffer().pixels[index] == frame.colorID();
return false;
}

public void draw(Frame frame) {
_draw(frontBuffer(), frame);
}

public void draw(PGraphics pGraphics, Frame frame) {
_draw(pGraphics, frame);
}

@Override
protected void _draw(Object context, Frame frame) {
PGraphics pGraphics = (PGraphics) context;
pGraphics.pushStyle();
pGraphics.pushMatrix();
/*
if(_frontShape != null)
pg.shape(_frontShape);
set(pg);
frontShape(pg);
//*/
///*
//TODO needs more thinking
switch (frame.highlighting()) {
case FRONT:
if (frame.isTracked())
pGraphics.scale(1.15f);
case NONE:
if (frame.frontShape() != null)
pGraphics.shape((PShape) frame.frontShape());
else
frame.graphics(pGraphics);
break;
case FRONT_BACK:
if (frame.frontShape() != null)
pGraphics.shape((PShape) frame.frontShape());
else
frame.frontGraphics(pGraphics);
if (frame.isTracked()) {
if (frame.backShape() != null)
pGraphics.shape((PShape) frame.backShape());
else
frame.backGraphics(pGraphics);
}
break;
case BACK:
if (frame.isTracked()) {
if (frame.backShape() != null)
pGraphics.shape((PShape) frame.backShape());
else
frame.backGraphics(pGraphics);
} else {
if (frame.frontShape() != null)
pGraphics.shape((PShape) frame.frontShape());
else
frame.frontGraphics(pGraphics);
}
break;
}
//*/
pGraphics.popStyle();
pGraphics.popMatrix();
}

protected void _drawBackBuffer(Object context, Frame frame) {
PGraphics pGraphics = (PGraphics) context;
if (frame.precision() == Frame.Precision.EXACT) {
pGraphics.pushStyle();
pGraphics.pushMatrix();

float r = (float) (frame.id() & 255) / 255.f;
float g = (float) ((frame.id() >> 8) & 255) / 255.f;
float b = (float) ((frame.id() >> 16) & 255) / 255.f;

// funny, only safe way. Otherwise break things horribly when setting shapes
// and there are more than one shape
pGraphics.shader(_triangleShader);
pGraphics.shader(_lineShader, PApplet.LINES);
pGraphics.shader(_pointShader, PApplet.POINTS);

_triangleShader.set("id", new PVector(r, g, b));
_lineShader.set("id", new PVector(r, g, b));
_pointShader.set("id", new PVector(r, g, b));

//pGraphics.pushStyle();
//pGraphics.pushMatrix();
/*
if (_backShape != null)
pg.shape(_backShape);
set(pg);
backShape(pg);
//*/
///*
if (frame.frontShape() != null)
pGraphics.shapeMode(frontBuffer().shapeMode);
if (frame.backShape() != null)
pGraphics.shape((PShape) frame.backShape());
else {
frame.graphics(pGraphics);
frame.backGraphics(pGraphics);
}
//*/
pGraphics.popStyle();
pGraphics.popMatrix();
}
}

/**
* Renders the scene onto {@code pGraphics} using the {@code eye} frame point of view and
* remaining frustum parameters. Useful to compute a shadow map taking the {@code eye} as
Expand Down

0 comments on commit 377d7b9

Please sign in to comment.