Java Code Examples for processing.core.PShape#setTexture()
The following examples show how to use
processing.core.PShape#setTexture() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void addTextureUVToShape(PShape shape, PImage img, float outerExtent, boolean xyMapping) { shape.setStroke(false); // shape.setFill(255); // This seems to jack up vertex shaders shape.setTextureMode(P.NORMAL); for (int i = 0; i < shape.getVertexCount(); i++) { PVector v = shape.getVertex(i); float uX = (xyMapping == true) ? v.x : v.z; shape.setTextureUV( i, P.map(uX, -outerExtent, outerExtent, 0, 1f), P.map(v.y, -outerExtent, outerExtent, 0, 1f) ); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); addTextureUVToShape(subShape, img, outerExtent, xyMapping); } if(img != null) shape.setTexture(img); }
Example 2
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void addTextureUVExactWidthHeight(PShape shape, PImage img, float width, float height) { shape.setStroke(false); // shape.setFill(255); // This seems to jack up vertex shaders shape.setTextureMode(P.NORMAL); for (int i = 0; i < shape.getVertexCount(); i++) { PVector v = shape.getVertex(i); shape.setTextureUV( i, P.map(v.x, -width/2f, width/2f, 0, 1f), P.map(v.y, -height/2f, height/2f, 0, 1f) ); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); addTextureUVExactWidthHeight(subShape, img, width, height); } if(img != null) shape.setTexture(img); }
Example 3
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void addTextureUVSpherical(PShape shape, PImage img) { shape.setStroke(false); // shape.setFill(255); // This seems to jack up vertex shaders shape.setTextureMode(P.NORMAL); for (int i = 0; i < shape.getVertexCount(); i++) { PVector p = shape.getVertex(i); // map spherical coordinate to uv coordinate :: https://stackoverflow.com/questions/19357290/convert-3d-point-on-sphere-to-uv-coordinate util.set(p.normalize()); float u = P.atan2(util.x, util.z) / P.TWO_PI + 0.5f; float v = P.asin(util.y) / P.PI + .5f; shape.setTextureUV(i, u, v); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); addTextureUVToShape(subShape, img); } if(img != null) shape.setTexture(img); }
Example 4
Source File: DwSoftBall3D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){ PShape shp = createShape(pg); shp.setTexture(null); shp.setFill(false); shp.setStroke(true); shp.setStroke(style.stroke_color); shp.setStrokeWeight(style.stroke_weight); setShapeWireframe(pg.parent, shp); }
Example 5
Source File: DwSoftBall2D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){ PShape shp = createShape(pg); shp.setTexture(null); shp.setFill(false); shp.setStroke(true); shp.setStroke(style.stroke_color); shp.setStrokeWeight(style.stroke_weight); setShapeWireframe(pg.parent, shp); }
Example 6
Source File: DwSoftGrid2D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){ PShape shp = pg.createShape(); displayGridXY(shp, texture_XYp); shp.setTexture(null); shp.setFill(false); shp.setStroke(true); shp.setStroke(style.stroke_color); shp.setStrokeWeight(style.stroke_weight); setShapeWireframe(pg.parent, shp); }
Example 7
Source File: DwSoftGrid3D.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){ PShape shp = createShape(pg); shp.setTexture(null); shp.setFill(false); shp.setStroke(true); shp.setStroke(style.stroke_color); shp.setStrokeWeight(style.stroke_weight); setShapeWireframe(pg.parent, shp); }
Example 8
Source File: DwFoldingSoftBody.java From PixelFlow with MIT License | 5 votes |
@Override public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){ PShape shp = createShape(pg); shp.setTexture(null); shp.setFill(false); shp.setStroke(true); shp.setStroke(style.stroke_color); shp.setStrokeWeight(style.stroke_weight); setShapeWireframe(pg.parent, shp); }
Example 9
Source File: GradientBlobs.java From haxademic with MIT License | 5 votes |
protected PShape newSphere(float size, PImage texture) { PShape shape = p.createShape(P.SPHERE, size); shape.setTexture(texture); // float extent = PShapeUtil.getSvgMaxExtent(shape); // PShapeUtil.addUVsToPShape(shape, extent); return shape; }
Example 10
Source File: PShapeSolid.java From haxademic with MIT License | 5 votes |
public static PShapeSolid newSolidSphere(float size, PImage texture) { PShape sphere = P.p.createShape(P.SPHERE, size).getTessellation(); sphere.setTexture(texture); PShapeUtil.addTextureUVSpherical(sphere, texture); PShape group = P.p.createShape(P.GROUP); group.addChild(sphere); return new PShapeSolid(group); }
Example 11
Source File: TextureAudioBlocksDeform.java From haxademic with MIT License | 5 votes |
protected void buildGrid() { // build the parent group gridShape = P.p.createShape(P.GROUP); // build the blocks int cols = 20; int rows = 10; float blockSize = 20f; float blockSpacing = blockSize * 2f; float halfW = cols/2 * blockSpacing; float halfH = rows/2 * blockSpacing; blocks = new PShape[cols * rows]; int buildIndex = 0; for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { float u = P.map(x, 0, cols - 1, 0.005f, 0.995f); float v = P.map(y, 0, rows - 1, 0.005f, 0.995f); PShape boxx = Shapes.createBoxSingleUV(blockSize, u, v); // PShape boxx = Shapes.createRectSingleUV(blockSize, u, v); boxx.setStroke(false); // boxx.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1))); boxx.setTexture(audioTexture.texture()); boxx.translate(x * blockSpacing - halfW, y * blockSpacing - halfH, 0); blocks[buildIndex] = boxx; buildIndex++; } } // normalize group shape PShapeUtil.centerShape(gridShape); PShapeUtil.scaleShapeToHeight(gridShape, height * 5f); }
Example 12
Source File: TextureBlocksSheet.java From haxademic with MIT License | 4 votes |
protected void buildGrid() { // build the parent group gridShape = P.p.createShape(P.GROUP); // build the blocks int cols = 20; int rows = 10; float blockSize = 15f; float blockSpacing = blockSize * 2f; float halfW = cols/2 * blockSpacing; float halfH = rows/2 * blockSpacing; blocks = new PShape[cols * rows]; int buildIndex = 0; for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { // PShape box = P.p.createShape(P.BOX, 10); // box.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1))); // box.translate(x, y, -MathUtil.randRangeDecimal(0, 1)); // gridShape.addChild(box); float u = P.map(x, 0, cols - 1, 0.005f, 0.995f); float v = P.map(y, 0, rows - 1, 0.005f, 0.995f); PShape boxx = Shapes.createBoxSingleUV(blockSize, u, v); // PShape boxx = Shapes.createRectSingleUV(blockSize, u, v); boxx.setStroke(false); // boxx.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1))); boxx.setTexture(audioTexture.texture()); boxx.translate(x * blockSpacing - halfW, y * blockSpacing - halfH, 0); blocks[buildIndex] = boxx; buildIndex++; // gridShape.addChild(boxx); } } // gridShape = Shapes.createSheet(40, audioTexture.texture()); // gridShape = gridShape.getTessellation(); // gridShape.setTexture(audioTexture.texture()); // normalize group shape PShapeUtil.centerShape(gridShape); PShapeUtil.scaleShapeToHeight(gridShape, height * 5f); // for (int i = 0; i < blocks.length; i++) { // PShapeUtil.scaleShapeToHeight(blocks[i], height * 0.2f); // } // debug // DebugView.setValue("grid cubes", cols * rows); // DebugView.setValue("grid vertices", PShapeUtil.vertexCount(gridShape)); // DebugView.setValue("grid max extent", PShapeUtil.getMaxExtent(gridShape)); }