MCPcopy Index your code
hub / github.com/processing/p5.js / addGeometry

Method addGeometry

src/webgl/GeometryBuilder.js:56–121  ·  view source on GitHub ↗

* @private * Adds a p5.Geometry to the builder's combined geometry, flattening * transformations.

(input)

Source from the content-addressed store, hash-verified

54 * transformations.
55 */
56 addGeometry(input) {
57 this.hasTransform = !this.renderer.states.uModelMatrix.mat4
58 .every((v, i) => v === this.identityMatrix.mat4[i]);
59
60 if (this.hasTransform) {
61 this.renderer.scratchMat3.inverseTranspose4x4(
62 this.renderer.states.uModelMatrix
63 );
64 }
65
66 let startIdx = this.geometry.vertices.length;
67 for (const v of this.transformVertices(input.vertices)) {
68 this.geometry.vertices.push(v);
69 }
70 for (const vn of this.transformNormals(input.vertexNormals)) {
71 this.geometry.vertexNormals.push(vn);
72 }
73 for (const val of input.uvs) {
74 this.geometry.uvs.push(val);
75 }
76
77 const inputUserVertexProps = input.userVertexProperties;
78 const builtUserVertexProps = this.geometry.userVertexProperties;
79 const numPreviousVertices =
80 this.geometry.vertices.length - input.vertices.length;
81
82 for (const propName in builtUserVertexProps){
83 if (propName in inputUserVertexProps){
84 continue;
85 }
86 const prop = builtUserVertexProps[propName];
87 const size = prop.getDataSize();
88 const numMissingValues = size * input.vertices.length;
89 const missingValues = Array(numMissingValues).fill(0);
90 prop.pushDirect(missingValues);
91 }
92 for (const propName in inputUserVertexProps){
93 const prop = inputUserVertexProps[propName];
94 const data = prop.getSrcArray();
95 const size = prop.getDataSize();
96 if (numPreviousVertices > 0 && !(propName in builtUserVertexProps)){
97 const numMissingValues = size * numPreviousVertices;
98 const missingValues = Array(numMissingValues).fill(0);
99 this.geometry.vertexProperty(propName, missingValues, size);
100 }
101 this.geometry.vertexProperty(propName, data, size);
102 }
103
104 if (this.renderer.states.fillColor) {
105 this.geometry.faces.push(
106 ...input.faces.map(f => f.map(idx => idx + startIdx))
107 );
108 }
109 if (this.renderer.states.strokeColor) {
110 for (const edge of input.edges.map(edge => edge.map(idx => idx + startIdx))) {
111 this.geometry.edges.push(edge);
112 }
113 }

Callers 2

addImmediateMethod · 0.95
addRetainedMethod · 0.95

Calls 9

transformVerticesMethod · 0.95
transformNormalsMethod · 0.95
inverseTranspose4x4Method · 0.80
getDataSizeMethod · 0.80
pushDirectMethod · 0.80
getSrcArrayMethod · 0.80
pushMethod · 0.45
fillMethod · 0.45
vertexPropertyMethod · 0.45

Tested by

no test coverage detected