refacto : updateObj remove double
This commit is contained in:
parent
3ab1c7b1ca
commit
a63d807856
|
@ -65,55 +65,13 @@ async function main() {
|
|||
instanceNumber: parseInt(instanceNumber),
|
||||
squareRotation: 0,
|
||||
};
|
||||
let length: number = 0;
|
||||
let buffers: any;
|
||||
updateObj(data, true);
|
||||
|
||||
const [
|
||||
positions,
|
||||
normals,
|
||||
uvs,
|
||||
indices,
|
||||
] = convert(data);
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let z = 0;
|
||||
let maxx = positions[0];
|
||||
let maxy = positions[1];
|
||||
let maxz = positions[2];
|
||||
let minx = positions[0];
|
||||
let miny = positions[1];
|
||||
let minz = positions[2];
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
if (i % 3 == 0) {
|
||||
if (positions[i] > maxx) {
|
||||
maxx = positions[i];
|
||||
} else if (positions[i] < minx) {
|
||||
minx = positions[i];
|
||||
}
|
||||
x += positions[i];
|
||||
} else if (i % 3 == 1) {
|
||||
if (positions[i] > maxy) {
|
||||
maxy = positions[i];
|
||||
} else if (positions[i] < miny) {
|
||||
miny = positions[i];
|
||||
}
|
||||
y += positions[i];
|
||||
} else {
|
||||
if (positions[i] > maxz) {
|
||||
maxz = positions[i];
|
||||
} else if (positions[i] < minz) {
|
||||
minz = positions[i];
|
||||
}
|
||||
z += positions[i];
|
||||
}
|
||||
}
|
||||
params.range = Math.max(maxx - minx, maxy - miny, maxz - minz);
|
||||
params.avg.x = x / (positions.length / 3);
|
||||
params.avg.y = y / (positions.length / 3);
|
||||
params.avg.z = z / (positions.length / 3);
|
||||
let length = indices.length;
|
||||
let [shaderProgram, fragmentShader]: any = initShaderProgram(gl,
|
||||
vsSource,
|
||||
fsSource4);
|
||||
|
||||
let programInfo: any = {
|
||||
program: shaderProgram,
|
||||
attribLocations: {
|
||||
|
@ -139,7 +97,6 @@ async function main() {
|
|||
};
|
||||
|
||||
let texture = loadTexture(gl, '/static/textures/racer.png');
|
||||
let buffers = initBuffers(gl, positions, indices, normals, uvs);
|
||||
let then = 0;
|
||||
let changed = false;
|
||||
|
||||
|
@ -167,8 +124,9 @@ async function main() {
|
|||
/**
|
||||
* Pushes a new obj file to the gl buffer
|
||||
* @param {string} data the obj file to push
|
||||
* @param {boolean} firstCall is it first object updated ?
|
||||
*/
|
||||
function updateObj(data: string) {
|
||||
function updateObj(data: string, firstCall: boolean = false) {
|
||||
const [
|
||||
positions,
|
||||
normals,
|
||||
|
@ -213,7 +171,9 @@ async function main() {
|
|||
params.avg.x = x / (positions.length / 3);
|
||||
params.avg.y = y / (positions.length / 3);
|
||||
params.avg.z = z / (positions.length / 3);
|
||||
if (!firstCall) {
|
||||
deleteBuffers(gl, buffers);
|
||||
}
|
||||
buffers = initBuffers(gl, positions, indices, normals, uvs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue