Java Code Examples for processing.core.PShape#getChildCount()
The following examples show how to use
processing.core.PShape#getChildCount() .
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 addTestStrokeToShape(PShape shape, float strokeWeight, float oscMult) { for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); int strokeReplace = P.p.color( 127 + 127f * P.sin(vertex.x * oscMult), 127 + 127f * P.sin(vertex.y * oscMult), 127 + 127f * P.sin(vertex.z * oscMult) ); shape.noFill(); shape.setStrokeWeight(i, 4); shape.setStroke(strokeReplace); } for (int j = 0; j < shape.getChildCount(); j++) { addTestStrokeToShape(shape.getChild(j), strokeWeight, oscMult); } }
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 | 6 votes |
public static void addVerticesToPointShape(PShape origShape, PShape newShape) { for (int i = 0; i < origShape.getVertexCount(); i++) { // check to see if vertex has already been added PVector v = origShape.getVertex(i); boolean foundDuplicateVertex = false; for (int j = 0; j < newShape.getVertexCount(); j++) { PVector addedVertex = newShape.getVertex(j); if(v.x == addedVertex.x && v.y == addedVertex.y && v.z == addedVertex.z) foundDuplicateVertex = true; } // if not already added, add it if(foundDuplicateVertex == false) newShape.vertex(v.x, v.y, v.z); } // recurse through children for (int j = 0; j < origShape.getChildCount(); j++) { addVerticesToPointShape(origShape.getChild(j), newShape); } }
Example 6
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void verticalTwistShape(PShape shape, float amp, float freq) { float height = PShapeUtil.getMaxAbsY(shape); for (int i = 0; i < shape.getVertexCount(); i++) { PVector v = shape.getVertex(i); float radius = MathUtil.getDistance(v.x, v.z, 0, 0); float twistAtY = ((v.y + radius) * freq) * 0.001f * amp; float newRads = MathUtil.getRadiansToTarget(0, 0, v.x, v.z) + twistAtY; shape.setVertex(i, radius * P.cos(newRads), v.y, radius * P.sin(newRads)); } for (int j = 0; j < shape.getChildCount(); j++) { verticalTwistShape(shape.getChild(j), amp, freq); } }
Example 7
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 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 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 10
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static float getMaxAbsX(PShape shape, float maxAbsXVertex) { // find mesh size height. this should only be used after centering the mesh for (int i = 0; i < shape.getVertexCount(); i++) { if(P.abs(shape.getVertex(i).x) > maxAbsXVertex) maxAbsXVertex = P.abs(shape.getVertex(i).x); } for (int j = 0; j < shape.getChildCount(); j++) { maxAbsXVertex = getMaxAbsX(shape.getChild(j), maxAbsXVertex); } return maxAbsXVertex; }
Example 11
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void getDepth(PShape shape, float[] minMax) { for (int i = 0; i < shape.getVertexCount(); i++) { if(shape.getVertex(i).z < minMax[0]) minMax[0] = shape.getVertex(i).z; if(shape.getVertex(i).z > minMax[1]) minMax[1] = shape.getVertex(i).z; } for (int j = 0; j < shape.getChildCount(); j++) { getDepth(shape.getChild(j), minMax); } }
Example 12
Source File: DwSoftBody.java From PixelFlow with MIT License | 5 votes |
private void removeChilds(PShape shp){ if(shp == null){ return; } int num_childs = shp.getChildCount(); for(int i = num_childs-1; i >= 0; i--){ removeChilds(shp.getChild(i)); shp.removeChild(i); } }
Example 13
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static float getMaxAbsZ(PShape shape, float maxAbsZVertex) { // find mesh size height. this should only be used after centering the mesh for (int i = 0; i < shape.getVertexCount(); i++) { if(P.abs(shape.getVertex(i).z) > maxAbsZVertex) maxAbsZVertex = P.abs(shape.getVertex(i).z); } for (int j = 0; j < shape.getChildCount(); j++) { maxAbsZVertex = getMaxAbsZ(shape.getChild(j), maxAbsZVertex); } return maxAbsZVertex; }
Example 14
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static int vertexCount(PShape shape) { int numVertices = shape.getVertexCount(); for (int j = 0; j < shape.getChildCount(); j++) { numVertices += vertexCount(shape.getChild(j)); } return numVertices; }
Example 15
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 16
Source File: IcosahedronQuadraticCurves.java From haxademic with MIT License | 5 votes |
public void drawCurves(PShape shape) { for (int i = 0; i < shape.getVertexCount() - 2; i+=3) { PVector v1 = shape.getVertex(i); PVector v2 = shape.getVertex(i+1); PVector v3 = shape.getVertex(i+2); float eqAmp = 1f + AudioIn.audioFreq(i); p.stroke(255f * (-0.75f + eqAmp)); // override for render // p.blendMode(PBlendModes.ADD); eqAmp = 1; p.stroke(185); p.beginShape(); p.vertex(v1.x, v1.y, v1.z); p.quadraticVertex(v2.x * eqAmp, v2.y * eqAmp, v2.z * eqAmp, v3.x, v3.y, v3.z); p.endShape(); p.beginShape(); p.vertex(v2.x, v2.y, v2.z); p.quadraticVertex(v1.x * eqAmp, v1.y * eqAmp, v1.z * eqAmp, v3.x, v3.y, v3.z); p.endShape(); p.beginShape(); p.vertex(v1.x, v1.y, v1.z); p.quadraticVertex(v3.x * eqAmp, v3.y * eqAmp, v3.z * eqAmp, v2.x, v2.y, v2.z); p.endShape(); } for (int j = 0; j < shape.getChildCount(); j++) { drawCurves(shape.getChild(j)); } }
Example 17
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 18
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 19
Source File: DwSoftBody.java From PixelFlow with MIT License | 5 votes |
protected void printChilds(PShape shp, String indent){ if(shp == null){ return; } int num_childs = shp.getChildCount(); System.out.println(indent+shp.getName()+": "+num_childs); for(int i = num_childs-1; i >= 0; i--){ printChilds(shp.getChild(i), indent+" "); } }
Example 20
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; }