Java Code Examples for processing.core.PShape#getChild()
The following examples show how to use
processing.core.PShape#getChild() .
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 float getMaxExtent(PShape shape, float outermostVertex) { // find mesh size extent to responsively scale the mesh for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); if(P.abs(vertex.x) > outermostVertex) outermostVertex = P.abs(vertex.x); if(P.abs(vertex.y) > outermostVertex) outermostVertex = P.abs(vertex.y); if(P.abs(vertex.z) > outermostVertex) outermostVertex = P.abs(vertex.z); } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); outermostVertex = getMaxExtent(subShape, outermostVertex); } return outermostVertex; }
Example 2
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 3
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 4
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 5
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static ArrayList<PVector> getUniqueVertices(PShape shape, ArrayList<PVector> uniqueVertices) { if(uniqueVertices == null) uniqueVertices = new ArrayList<PVector>(); for (int i = 0; i < shape.getVertexCount(); i++) { PVector point = shape.getVertex(i); if(hasVertex(uniqueVertices, point) == false) { uniqueVertices.add( point ); } } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); getUniqueVertices(subShape, uniqueVertices); } return uniqueVertices; }
Example 6
Source File: Skylight_BulletPhysics_Cubes.java From PixelFlow with MIT License | 5 votes |
private void fixBoxNormals(PShape box){ PShape face; face = box.getChild(1); for(int i = 0; i < 4; i++){ face.setNormal(i, -1, 0, 0); } face = box.getChild(3); for(int i = 0; i < 4; i++){ face.setNormal(i, +1, 0, 0); } }
Example 7
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void scaleVertices(PShape s, float x, float y, float z) { for (int i = 0; i < s.getVertexCount(); i++) { PVector curVertex = s.getVertex(i); s.setVertex(i, curVertex.x * x, curVertex.y * y, curVertex.z * z); } for (int j = 0; j < s.getChildCount(); j++) { PShape subShape = s.getChild(j); scaleVertices(subShape, x, y, z); } }
Example 8
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void scaleVertices(PShape s, float scale) { for (int i = 0; i < s.getVertexCount(); i++) { PVector curVertex = s.getVertex(i); s.setVertex(i, curVertex.x * scale, curVertex.y * scale, curVertex.z * scale); } for (int j = 0; j < s.getChildCount(); j++) { PShape subShape = s.getChild(j); scaleVertices(subShape, scale); } }
Example 9
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void offsetShapeVertices(PShape s, float xOffset, float yOffset, float zOffset) { for (int i = 0; i < s.getVertexCount(); i++) { PVector vertex = s.getVertex(i); s.setVertex(i, vertex.x + xOffset, vertex.y + yOffset, vertex.z + zOffset); } for (int i = 0; i < s.getChildCount(); i++) { PShape subShape = s.getChild(i); offsetShapeVertices(subShape, xOffset, yOffset, zOffset); } }
Example 10
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void getShapeExtents(PShape shape, float[] extents) { for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); if(extents[0] == 0 || vertex.x < extents[0]) extents[0] = vertex.x; if(extents[1] == 0 || vertex.x > extents[1]) extents[1] = vertex.x; if(extents[2] == 0 || vertex.y < extents[2]) extents[2] = vertex.y; if(extents[3] == 0 || vertex.y > extents[3]) extents[3] = vertex.y; if(extents[4] == 0 || vertex.z < extents[4]) extents[4] = vertex.z; if(extents[5] == 0 || vertex.z > extents[5]) extents[5] = vertex.z; } for (int i = 0; i < shape.getChildCount(); i++) { PShape subShape = shape.getChild(i); getShapeExtents(subShape, extents); } }
Example 11
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static PShape addShapesByColor(PShape shape, float searchR, float searchG, float searchB, PShape container, float closenessThreshold) { for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); if(colorMatchNormalized(searchR, searchG, searchB, subShape.getFill(0), closenessThreshold)) { container.addChild(subShape); } // getShapeFromColor(shape.getChild(j), searchR, searchG, searchB); } return container; }
Example 12
Source File: PShapeSvgSubShapeTest.java From haxademic with MIT License | 5 votes |
public void removeShapeChild( PShape parent, PShape child ) { for( int i = 0; i < parent.getChildCount(); i++ ) { // for( PShape child: parent.getChildren() ) { if( parent.getChild(i) == child ) { parent.removeChild(i); } } }
Example 13
Source File: Demo_VectorFlyer.java From haxademic with MIT License | 5 votes |
public void addPointsToAttractors(PShape shape) { for (int i = 0; i < shape.getVertexCount(); i++) { PVector point = shape.getVertex(i); if(attractorExists(point) == false) { attractors.add( point ); attractorsCount++; DebugView.setValue("attractorsCount", attractorsCount); } } for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); addPointsToAttractors(subShape); } }
Example 14
Source File: Skylight_BulletPhysics_Basic.java From PixelFlow with MIT License | 5 votes |
private void fixBoxNormals(PShape box){ PShape face; face = box.getChild(1); for(int i = 0; i < 4; i++){ face.setNormal(i, -1, 0, 0); } face = box.getChild(3); for(int i = 0; i < 4; i++){ face.setNormal(i, +1, 0, 0); } }
Example 15
Source File: Skylight_BulletPhysics_TowerDemolition.java From PixelFlow with MIT License | 5 votes |
private void fixBoxNormals(PShape box){ PShape face; face = box.getChild(1); for(int i = 0; i < 4; i++){ face.setNormal(i, -1, 0, 0); } face = box.getChild(3); for(int i = 0; i < 4; i++){ face.setNormal(i, +1, 0, 0); } }
Example 16
Source File: Skylight_BulletPhysics_MengerSponge.java From PixelFlow with MIT License | 5 votes |
private void fixBoxNormals(PShape box){ PShape face; face = box.getChild(1); for(int i = 0; i < 4; i++){ face.setNormal(i, -1, 0, 0); } face = box.getChild(3); for(int i = 0; i < 4; i++){ face.setNormal(i, +1, 0, 0); } }
Example 17
Source File: Skylight_BulletPhysics_CellFracture.java From PixelFlow with MIT License | 5 votes |
private void fixBoxNormals(PShape box){ PShape face; face = box.getChild(1); for(int i = 0; i < 4; i++){ face.setNormal(i, -1, 0, 0); } face = box.getChild(3); for(int i = 0; i < 4; i++){ face.setNormal(i, +1, 0, 0); } }
Example 18
Source File: PShapeUtil.java From haxademic with MIT License | 4 votes |
public static PShape createExtrudedShape(PShape shape, float depth, PShape newShape) { if(newShape == null) newShape = P.p.createShape(); newShape.beginShape(P.TRIANGLES); // top for (int i = 0; i < shape.getVertexCount() - 3; i+=3) { // copy triangle vertices & UV coords PVector v1 = shape.getVertex(i); PVector v2 = shape.getVertex(i+1); PVector v3 = shape.getVertex(i+2); float texU1 = shape.getTextureU(i); float texV1 = shape.getTextureU(i); float texU2 = shape.getTextureU(i+1); float texV2 = shape.getTextureU(i+1); float texU3 = shape.getTextureU(i+2); float texV3 = shape.getTextureU(i+2); // half depth to keep new model centered on z-axis float halfDepth = depth / 2f; // top newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1); newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2); newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3); // bottom newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1); newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2); newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3); // walls // wall 1 newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1); newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1); newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2); newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1); newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2); newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2); // wall 2 newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2); newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2); newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3); newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2); newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3); newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3); // wall 3 newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3); newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3); newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1); newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3); newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1); newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1); } newShape.endShape(); // recurse through original shape children if nested shapes for (int j = 0; j < shape.getChildCount(); j++) { PShape subShape = shape.getChild(j); createExtrudedShape(subShape, depth, newShape); } return newShape; }