Ich habe eine große Puffer Geometrie, etwa 4 Millionen Eckpunkte, die eine kleine Fläche der Schattierung aktualisiert werden muss. Ich aktualisiere derzeit zufällig die VertexNormals, aber es verursacht eine Verzögerung. Ich habe versucht, die updateRange.offset der Geometrie (How to quickly update a large BufferGeometry?) zu verwenden, aber in den Quellcode schauend, glaube ich nicht, dass dies die vertexNormals() Funktion beeinflußt.DREI JS computeVertexNormals() Leistung
Schleife mich 1000 Mal:
GRID.geometry.attributes.position.array[ (array_position + 2) ] = _position[2] - WEBGLzTranslate ;
GRID.geometry.attributes.color.array[ (array_position) + 0 ] = color.r;
GRID.geometry.attributes.color.array[ (array_position) + 1 ] = color.g;
GRID.geometry.attributes.color.array[ (array_position) + 2 ] = color.b;
dann eingestellt Update:
if(minArrayPosition < Infinity){
GRID.geometry.attributes.position.updateRange = {};
GRID.geometry.attributes.position.offset = minArrayPosition;
GRID.geometry.attributes.position.count = maxArrayPosition - minArrayPosition;
GRID.geometry.attributes.position.needsUpdate = true;
GRID.geometry.verticesNeedUpdate = true;
}
GRID.geometry.attributes.color.needsUpdate = true;
GRID.material.needsUpdate = true;
if(Math.random() > .99)
{
GRID.geometry.computeFaceNormals();
GRID.geometry.computeVertexNormals();
console.log('Updating Shadding');
}
Idealerweise denke ich, Ich mag würde den Bereich Arbeit für die vertexNormals haben. vielleicht irgendwo in hier (BufferGeometry.js: 657):
if (attributes.position) {
var positions = attributes.position.array;
if (attributes.normal === undefined) {
this.addAttribute('normal', new BufferAttribute(new Float32Array(positions.length), 3));
} else {
// reset existing normals to zero
var array = attributes.normal.array;
for (var i = 0, il = array.length; i < il; i ++) {
array[ i ] = 0;
}
}
var normals = attributes.normal.array;
var vA, vB, vC,
pA = new Vector3(),
pB = new Vector3(),
pC = new Vector3(),
cb = new Vector3(),
ab = new Vector3();
// indexed elements
if (index) {
var indices = index.array;
if (groups.length === 0) {
this.addGroup(0, indices.length);
}
for (var j = 0, jl = groups.length; j < jl; ++ j) {
var group = groups[ j ];
var start = group.start;
var count = group.count;
for (var i = start, il = start + count; i < il; i += 3) {
vA = indices[ i + 0 ] * 3;
vB = indices[ i + 1 ] * 3;
vC = indices[ i + 2 ] * 3;
pA.fromArray(positions, vA);
pB.fromArray(positions, vB);
pC.fromArray(positions, vC);
cb.subVectors(pC, pB);
ab.subVectors(pA, pB);
cb.cross(ab);
normals[ vA ] += cb.x;
normals[ vA + 1 ] += cb.y;
normals[ vA + 2 ] += cb.z;
normals[ vB ] += cb.x;
normals[ vB + 1 ] += cb.y;
normals[ vB + 2 ] += cb.z;
normals[ vC ] += cb.x;
normals[ vC + 1 ] += cb.y;
normals[ vC + 2 ] += cb.z;
}
}
Sollte ich stattdessen in Morphing-Materialien suchen ?? Danke
Klingt wie Sie Ihre eigene Implementierung von 'computeVertexNormals()' brauchen, zu schreiben, die die Grenzen tut folgen Sie festlegen. Das Einfrieren ist, weil JavaScript nichts anderes ausführen kann, bis die aktuelle Funktion ihre Verarbeitung beendet oder auf ein Ereignis wartet. Eine lange Rechenschleife "friert" den Browser für die gesamte Dauer ein. – Leeft
vielleicht versuchen, computeVertexNormals asynch in einem Set-Intervall-Funktion, die sich selbst nach dem Ausführen beendet einmal ausgeführt? Ich könnte es dann aussperren, aber würde Atleast die Verzögerung nicht so viel sehen? Ill sendet computeVertexNormals ({offset: Int, Bereich: int}) an Git als Feature-Anforderung – LrakWortep