Java Code Examples for processing.core.PShape#getVertexCount()
The following examples show how to use
processing.core.PShape#getVertexCount() .
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: Impeach.java From haxademic with MIT License | 6 votes |
public void addFillToShape(PShape shape, float oscMult) { for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); float zFade = P.map(vertex.z, 50, -50, 1, 0); int fillReplace = P.p.color( (127 + 127f * P.sin(vertex.x * oscMult)) * zFade, (127 + 127f * P.sin(vertex.y * oscMult)) * zFade, (127 + 127f * P.sin(vertex.z * oscMult)) * zFade ); shape.setFill(i, fillReplace); shape.noStroke(); } for (int j = 0; j < shape.getChildCount(); j++) { addFillToShape(shape.getChild(j), oscMult); } }
Example 2
Source File: HeadSkullRenderVirus.java From haxademic with MIT License | 6 votes |
protected void buildHeadModel() { // load model skullObj = p.loadShape( FileUtil.getPath("models/skull-realistic.obj")); objOrig = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj")); obj = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj")); PShapeUtil.scaleShapeToHeight(skullObj, p.height * 0.78f * 2f); PShapeUtil.scaleShapeToHeight(objOrig, p.height * 0.7f * 2f); PShapeUtil.scaleShapeToHeight(obj, p.height * 0.7f * 2f); // get centers of each face objFaceCenters = new PVector[obj.getChildCount()]; for (int i = 0; i < obj.getChildren().length; i++ ) { PShape child = obj.getChild(i); if(child.getVertexCount() == 3) { objFaceCenters[i] = MathUtil.computeTriangleCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2) ).copy(); } else { objFaceCenters[i] = MathUtil.computeQuadCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2), child.getVertex(3) ).copy(); } } maxHeadExtent = PShapeUtil.getMaxExtent(obj); }
Example 3
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 4
Source File: PShapeUtil.java From haxademic with MIT License | 6 votes |
public static void setShapeMaterialTransparent(PShape shape, float searchR, float searchG, float searchB, float alphaReplace) { float thresh = 0.02f; for (int i = 0; i < shape.getVertexCount(); i++) { // get normalized material components float red = P.p.red(shape.getFill(i)); float green = P.p.green(shape.getFill(i)); float blue = P.p.blue(shape.getFill(i)); // check distance from supplied color if(P.abs(red / 255f - searchR) < thresh && P.abs(green / 255f - searchG) < thresh && P.abs(blue / 255f - searchB) < thresh) { shape.setFill(i, P.p.color(red, green, blue, alphaReplace * 255f)); } } for (int j = 0; j < shape.getChildCount(); j++) { setShapeMaterialTransparent(shape.getChild(j), searchR, searchG, searchB, alphaReplace); } }
Example 5
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 6
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 7
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 8
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void addTestFillToShape(PShape shape, float oscMult) { for (int i = 0; i < shape.getVertexCount(); i++) { PVector vertex = shape.getVertex(i); int fillReplace = 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.setFill(i, fillReplace); shape.noStroke(); } for (int j = 0; j < shape.getChildCount(); j++) { addTestFillToShape(shape.getChild(j), oscMult); } }
Example 9
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void replaceShapeMaterial(PShape shape, float searchR, float searchG, float searchB, int fillReplace, int strokeReplace, float closenessThreshold) { // shape.setStrokeWeight(4); // shape.setStroke(strokeReplace); for (int i = 0; i < shape.getVertexCount(); i++) { if(colorMatchNormalized(searchR, searchG, searchB, shape.getFill(i), closenessThreshold)) { shape.setFill(i, fillReplace); shape.setStrokeWeight(i, 4); shape.setStroke(strokeReplace); } } for (int j = 0; j < shape.getChildCount(); j++) { replaceShapeMaterial(shape.getChild(j), searchR, searchG, searchB, fillReplace, strokeReplace, closenessThreshold); } }
Example 10
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 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: 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 13
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static void getWidth(PShape shape, float[] minMax) { for (int i = 0; i < shape.getVertexCount(); i++) { if(shape.getVertex(i).x < minMax[0]) minMax[0] = shape.getVertex(i).x; if(shape.getVertex(i).x > minMax[1]) minMax[1] = shape.getVertex(i).x; } for (int j = 0; j < shape.getChildCount(); j++) { getWidth(shape.getChild(j), minMax); } }
Example 14
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 15
Source File: PShapeUtil.java From haxademic with MIT License | 5 votes |
public static float getMaxAbsY(PShape shape, float maxAbsYVertex) { // 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).y) > maxAbsYVertex) maxAbsYVertex = P.abs(shape.getVertex(i).y); } for (int j = 0; j < shape.getChildCount(); j++) { maxAbsYVertex = getMaxAbsY(shape.getChild(j), maxAbsYVertex); } return maxAbsYVertex; }
Example 16
Source File: HaxMapDrawingTool.java From haxademic with MIT License | 5 votes |
public void drawExistingShapes() { // draw already-drawn shapes p.noFill(); p.stroke(255); for (int i=0; i < _shapes.size(); i++) { // get shape and set audio-reactive fill -------------- PShape shape = _shapes.get(i); shape.setFill(p.color(255, AudioIn.audioFreq((i * 10 + 10)) * 2000)); p.shape( shape ); if( _debugging == true ) { // draw wireframe and handles ------------------------- PVector v = null; PVector nextV = null; int numVertices = shape.getVertexCount(); for (int j = 0; j < shape.getVertexCount(); j++) { v = shape.getVertex(j); p.ellipse( v.x, v.y, 6, 6 ); if( j < numVertices - 1 ) { nextV = shape.getVertex(j+1); p.line( v.x, v.y, nextV.x, nextV.y ); } } p.line( shape.getVertex(0).x, shape.getVertex(0).y, shape.getVertex(numVertices-1).x, shape.getVertex(numVertices-1).y ); } } }
Example 17
Source File: HeadSkullRender.java From haxademic with MIT License | 5 votes |
protected void firstFrame() { centerX = p.width/2; centerY = p.height/2; // controls UI.addSlider(emissiveMaterial, 13f, 0, 255, 0.5f, false); UI.addSlider(ambientLight, 24f, 0, 255, 0.5f, false); UI.addSlider(specularMaterial, 150, 0, 255, 0.5f, false); UI.addSlider(specularLight, 200, 0, 255, 0.5f, false); UI.addSlider(shininessVal, 40f, 0, 100, 0.5f, false); UI.addSlider(lightsFalloffVal, 0.005f, 0, 0.01f, 0.0001f, false); UI.addSlider(lightsFalloffConstantVal, 0.017f, 0, 2f, 0.01f, false); UI.addSlider(spotLightConeAngle, 0.2f, 0, P.TWO_PI, 0.01f, false); UI.addSlider(spotLightConcentration, 100f, 0, 1000f, 1f, false); // load model skullObj = p.loadShape( FileUtil.getPath("models/skull-realistic.obj")); objOrig = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj")); obj = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj")); PShapeUtil.scaleShapeToHeight(skullObj, p.height * 0.78f * 2f); PShapeUtil.scaleShapeToHeight(objOrig, p.height * 0.7f * 2f); PShapeUtil.scaleShapeToHeight(obj, p.height * 0.7f * 2f); // get centers of each face objFaceCenters = new PVector[obj.getChildCount()]; for (int i = 0; i < obj.getChildren().length; i++ ) { PShape child = obj.getChild(i); if(child.getVertexCount() == 3) { objFaceCenters[i] = MathUtil.computeTriangleCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2) ).copy(); } else { objFaceCenters[i] = MathUtil.computeQuadCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2), child.getVertex(3) ).copy(); } } maxObjExtent = PShapeUtil.getMaxExtent(obj); }
Example 18
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 19
Source File: HeadSkullRender.java From haxademic with MIT License | 4 votes |
protected void drawObj() { //////////////// // set context //////////////// p.pushMatrix(); p.translate(p.width/2, p.height * 0.45f, -p.width); p.rotateZ(P.PI); p.rotateY(P.sin(P.TWO_PI * _progress) * 0.45f); //////////////// // draw skull //////////////// p.pushMatrix(); p.translate(0, p.height * -0.03f, 0); skullObj.disableStyle(); p.fill(120 + 30f * P.sin(_progress * P.TWO_PI * 50f), 0, 0); // p.scale(0.73f + 0.1f * P.sin(P.TWO_PI * _progress)); p.scale(0.71f); p.shape(skullObj); p.popMatrix(); //////////////// // draw head //////////////// p.pushMatrix(); p.translate(0, p.height * -0.18f, 12); p.fill(255); // p.scale(0.9f + 0.2f * P.sin(P.PI + P.TWO_PI * _progress)); // sweeping x progress for distance check float xProg = P.map(_progress, 0, 1, -maxObjExtent * 1.3f, maxObjExtent * 1.3f); // shrink/grow adjusted mesh for (int i = 0; i < obj.getChildren().length; i++ ) { PShape child = obj.getChild(i); PShape childOrig = objOrig.getChild(i); for(int vIndex = 0; vIndex < child.getVertexCount(); vIndex++) { // PVector vertex = child.getVertex(vIndex); PVector vertexOrig = childOrig.getVertex(vIndex); // float amp = 1.2f + 0.2f * P.sin((float)i/100f + _progress * P.TWO_PI); // float amp = 1.2f + 0.2f * P.sin((float)i/100f + P.abs(vertexOrig.x) + P.abs(vertexOrig.y) + P.abs(vertexOrig.z) + _progress * P.TWO_PI); // float amp = 1; // child.setVertex(vIndex, vertexOrig.x * amp, vertexOrig.y * amp, vertexOrig.z * amp); // float indexOffset = (float)i / 100f; // float easedProgress = Penner.easeInOutCubic(0.5f + 0.5f * P.sin(indexOffset + _progress * P.TWO_PI), 0, 1, 1); // get distance to sweeping x coord float dist = MathUtil.getDistance(xProg, 0, objFaceCenters[i].x, 0); float easedProgress = 0; float distanceMax = maxObjExtent * 0.65f; if(P.abs(dist) < distanceMax) { // easedProgress = P.map(dist, distanceMax, 0, 0, 1); easedProgress = Penner.easeInOutExpo(P.map(dist, distanceMax, 0, 0, 1), 0, 1, 1); } // set vertices of manipulated object child.setVertex( vIndex, P.map(easedProgress, 0, 1, vertexOrig.x, objFaceCenters[i].x), P.map(easedProgress, 0, 1, vertexOrig.y, objFaceCenters[i].y), P.map(easedProgress, 0, 1, vertexOrig.z, objFaceCenters[i].z) ); } } // draw debug box for x-distance check on shrinking triangles if(UI.active()) { p.pushMatrix(); p.translate(xProg, 300); p.fill(255); p.box(20); p.popMatrix(); } // obj.disableStyle(); p.fill(255,185,40); p.shape(obj); p.popMatrix(); // reset context p.popMatrix(); }
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; }