2020-11-22 14:09:28 +00:00
|
|
|
// @ts-ignore
|
2020-11-24 18:18:45 +00:00
|
|
|
import {convert} from './objparser';
|
2020-11-24 11:10:57 +00:00
|
|
|
import $ from 'jquery';
|
2020-11-25 20:07:21 +00:00
|
|
|
import vsSource from './shaders/shader.vert';
|
|
|
|
import fsSource from './shaders/blackandwhite.frag';
|
|
|
|
import fsSource2 from './shaders/colored.frag';
|
|
|
|
import fsSource3 from './shaders/grey.frag';
|
|
|
|
import fsSource4 from './shaders/texture.frag';
|
|
|
|
import fsSource5 from './shaders/sobel.frag';
|
2020-11-24 11:10:57 +00:00
|
|
|
|
2020-11-24 12:53:30 +00:00
|
|
|
import {initBuffers, deleteBuffers} from './buffers';
|
2020-11-24 11:10:57 +00:00
|
|
|
import {initShaderProgram} from './shaders';
|
|
|
|
import {changeFragmentShader} from './changeshader';
|
2020-11-24 18:18:45 +00:00
|
|
|
import {loadTexture} from './texture';
|
2020-11-26 08:11:02 +00:00
|
|
|
import {initMatrices} from './matrix';
|
2020-11-22 14:16:08 +00:00
|
|
|
|
2020-11-22 14:09:28 +00:00
|
|
|
main();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The program purpose is encapsulated in a main function
|
|
|
|
*/
|
2020-11-24 12:53:30 +00:00
|
|
|
async function main() {
|
2020-11-22 14:09:28 +00:00
|
|
|
const canvas: any = document.querySelector('#glCanvas')!;
|
2020-11-24 13:10:16 +00:00
|
|
|
const gl = canvas.getContext('webgl');
|
2020-11-22 14:09:28 +00:00
|
|
|
|
|
|
|
if (gl == null) {
|
|
|
|
canvas.parentNode.removeChild(canvas);
|
|
|
|
document.getElementById('root')!.insertAdjacentHTML('beforeend',
|
|
|
|
`<p>Unable to initialize WebGL. Your browser or machine may not
|
|
|
|
support it.</p>`);
|
|
|
|
}
|
|
|
|
|
2020-11-24 12:53:30 +00:00
|
|
|
/**
|
|
|
|
* Fetch an obj file
|
|
|
|
* @param {string} url the url to fetch the object from
|
|
|
|
* @return {string} the raw data of the obj file
|
|
|
|
*/
|
|
|
|
async function getObj(url: string) {
|
|
|
|
const response = await fetch(url);
|
|
|
|
const data = await response.text();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2020-11-25 11:43:13 +00:00
|
|
|
const data = await getObj('/static/objs/racer.obj');
|
2020-11-25 12:51:39 +00:00
|
|
|
const distance: any = $('#distance').val();
|
|
|
|
const distanceFine: any = $('#distancefine').val();
|
2020-11-25 17:58:49 +00:00
|
|
|
const instanceNumber: any = $('#instance').val();
|
2020-11-24 21:12:32 +00:00
|
|
|
const params: any = {
|
2020-11-25 12:51:39 +00:00
|
|
|
distance: parseFloat(distance) + parseFloat(distanceFine),
|
2020-11-24 21:12:32 +00:00
|
|
|
circleSize: $('#circlesize').val(),
|
|
|
|
fov: $('#fov').val(),
|
|
|
|
avg: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
z: 0,
|
|
|
|
},
|
2020-11-25 17:58:49 +00:00
|
|
|
range: 0,
|
2020-11-25 11:43:13 +00:00
|
|
|
rot: {
|
|
|
|
x: $('#rotx').val(),
|
|
|
|
y: $('#roty').val(),
|
|
|
|
z: $('#rotz').val(),
|
|
|
|
},
|
2020-11-25 12:45:25 +00:00
|
|
|
rotSpeed: $('#rotspeed').val(),
|
2020-11-25 17:58:49 +00:00
|
|
|
instanceNumber: parseInt(instanceNumber),
|
2020-11-26 08:11:02 +00:00
|
|
|
squareRotation: 0,
|
2020-11-24 21:12:32 +00:00
|
|
|
};
|
|
|
|
|
2020-11-24 12:53:30 +00:00
|
|
|
const [
|
|
|
|
positions,
|
|
|
|
normals,
|
|
|
|
uvs,
|
|
|
|
indices,
|
|
|
|
] = convert(data);
|
2020-11-24 21:12:32 +00:00
|
|
|
let x = 0;
|
|
|
|
let y = 0;
|
|
|
|
let z = 0;
|
2020-11-25 17:58:49 +00:00
|
|
|
let maxx = positions[0];
|
|
|
|
let maxy = positions[1];
|
|
|
|
let maxz = positions[2];
|
|
|
|
let minx = positions[0];
|
|
|
|
let miny = positions[1];
|
|
|
|
let minz = positions[2];
|
2020-11-24 21:12:32 +00:00
|
|
|
for (let i = 0; i < positions.length; i++) {
|
|
|
|
if (i % 3 == 0) {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxx) {
|
|
|
|
maxx = positions[i];
|
|
|
|
} else if (positions[i] < minx) {
|
|
|
|
minx = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
x += positions[i];
|
|
|
|
} else if (i % 3 == 1) {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxy) {
|
|
|
|
maxy = positions[i];
|
|
|
|
} else if (positions[i] < miny) {
|
|
|
|
miny = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
y += positions[i];
|
|
|
|
} else {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxz) {
|
|
|
|
maxz = positions[i];
|
|
|
|
} else if (positions[i] < minz) {
|
|
|
|
minz = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
z += positions[i];
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 17:58:49 +00:00
|
|
|
params.range = Math.max(maxx - minx, maxy - miny, maxz - minz);
|
2020-11-24 21:12:32 +00:00
|
|
|
params.avg.x = x / (positions.length / 3);
|
|
|
|
params.avg.y = y / (positions.length / 3);
|
|
|
|
params.avg.z = z / (positions.length / 3);
|
2020-11-24 12:53:30 +00:00
|
|
|
let length = indices.length;
|
|
|
|
let [shaderProgram, fragmentShader]: any = initShaderProgram(gl,
|
|
|
|
vsSource,
|
2020-11-24 18:18:45 +00:00
|
|
|
fsSource4);
|
2020-11-24 12:53:30 +00:00
|
|
|
|
|
|
|
let programInfo: any = {
|
|
|
|
program: shaderProgram,
|
|
|
|
attribLocations: {
|
|
|
|
vertexPosition: gl.getAttribLocation(shaderProgram,
|
|
|
|
'aVertexPosition'),
|
|
|
|
vertexNormal: gl.getAttribLocation(shaderProgram,
|
|
|
|
'aVertexNormal'),
|
2020-11-24 18:18:45 +00:00
|
|
|
textureCoord: gl.getAttribLocation(shaderProgram,
|
|
|
|
'aTextureCoord'),
|
2020-11-24 12:53:30 +00:00
|
|
|
},
|
|
|
|
uniformLocations: {
|
|
|
|
projectionMatrix: gl.getUniformLocation(
|
|
|
|
shaderProgram, 'uProjectionMatrix'),
|
|
|
|
viewMatrix: gl.getUniformLocation(
|
|
|
|
shaderProgram, 'uviewMatrix'),
|
|
|
|
modelMatrix: gl.getUniformLocation(
|
|
|
|
shaderProgram, 'umodelMatrix'),
|
2020-11-25 11:43:13 +00:00
|
|
|
normalModelMatrix: gl.getUniformLocation(
|
|
|
|
shaderProgram, 'unormalModelMatrix'),
|
2020-11-24 18:18:45 +00:00
|
|
|
uSampler: gl.getUniformLocation(
|
|
|
|
shaderProgram, 'uSampler'),
|
2020-11-24 12:53:30 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-25 11:43:13 +00:00
|
|
|
let texture = loadTexture(gl, '/static/textures/racer.png');
|
2020-11-24 18:18:45 +00:00
|
|
|
let buffers = initBuffers(gl, positions, indices, normals, uvs);
|
2020-11-24 12:53:30 +00:00
|
|
|
let then = 0;
|
|
|
|
let changed = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the scene repeatedly
|
|
|
|
* @param {number} now the current time
|
|
|
|
*/
|
|
|
|
function render(now: any) {
|
|
|
|
now *= 0.001;
|
|
|
|
const deltaTime = now - then;
|
2020-11-26 08:11:02 +00:00
|
|
|
params.squareRotation += deltaTime;
|
2020-11-24 12:53:30 +00:00
|
|
|
if (now >= 1 && changed == false) {
|
|
|
|
changed = true;
|
2020-11-22 14:09:28 +00:00
|
|
|
}
|
2020-11-24 12:53:30 +00:00
|
|
|
then = now;
|
|
|
|
drawScene(gl,
|
|
|
|
programInfo,
|
|
|
|
buffers,
|
|
|
|
length,
|
2020-11-24 21:12:32 +00:00
|
|
|
params,
|
2020-11-24 18:18:45 +00:00
|
|
|
texture);
|
2020-11-24 12:53:30 +00:00
|
|
|
requestAnimationFrame(render);
|
|
|
|
}
|
2020-11-24 11:10:57 +00:00
|
|
|
|
2020-11-24 15:30:59 +00:00
|
|
|
/**
|
|
|
|
* Pushes a new obj file to the gl buffer
|
|
|
|
* @param {string} data the obj file to push
|
|
|
|
*/
|
|
|
|
function updateObj(data: string) {
|
|
|
|
const [
|
|
|
|
positions,
|
|
|
|
normals,
|
|
|
|
uvs,
|
|
|
|
indices,
|
|
|
|
] = convert(data);
|
|
|
|
length = indices.length;
|
2020-11-24 21:12:32 +00:00
|
|
|
let x = 0;
|
|
|
|
let y = 0;
|
|
|
|
let z = 0;
|
2020-11-25 17:58:49 +00:00
|
|
|
let maxx = positions[0];
|
|
|
|
let maxy = positions[1];
|
|
|
|
let maxz = positions[2];
|
|
|
|
let minx = positions[0];
|
|
|
|
let miny = positions[1];
|
|
|
|
let minz = positions[2];
|
2020-11-24 21:12:32 +00:00
|
|
|
for (let i = 0; i < positions.length; i++) {
|
|
|
|
if (i % 3 == 0) {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxx) {
|
|
|
|
maxx = positions[i];
|
|
|
|
} else if (positions[i] < minx) {
|
|
|
|
minx = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
x += positions[i];
|
|
|
|
} else if (i % 3 == 1) {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxy) {
|
|
|
|
maxy = positions[i];
|
|
|
|
} else if (positions[i] < miny) {
|
|
|
|
miny = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
y += positions[i];
|
|
|
|
} else {
|
2020-11-25 17:58:49 +00:00
|
|
|
if (positions[i] > maxz) {
|
|
|
|
maxz = positions[i];
|
|
|
|
} else if (positions[i] < minz) {
|
|
|
|
minz = positions[i];
|
|
|
|
}
|
2020-11-24 21:12:32 +00:00
|
|
|
z += positions[i];
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 17:58:49 +00:00
|
|
|
params.range = Math.max(maxx - minx, maxy - miny, maxz - minz);
|
2020-11-24 21:12:32 +00:00
|
|
|
params.avg.x = x / (positions.length / 3);
|
|
|
|
params.avg.y = y / (positions.length / 3);
|
|
|
|
params.avg.z = z / (positions.length / 3);
|
2020-11-24 15:30:59 +00:00
|
|
|
deleteBuffers(gl, buffers);
|
2020-11-24 18:18:45 +00:00
|
|
|
buffers = initBuffers(gl, positions, indices, normals, uvs);
|
2020-11-24 15:30:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 12:53:30 +00:00
|
|
|
$(function() {
|
2020-11-24 21:12:32 +00:00
|
|
|
$('#distance').on('input', function() {
|
|
|
|
const distance: any = $('#distance').val();
|
2020-11-25 12:51:39 +00:00
|
|
|
const distanceFine: any = $('#distancefine').val();
|
|
|
|
params.distance = parseFloat(distance) + parseFloat(distanceFine);
|
|
|
|
});
|
|
|
|
$('#distancefine').on('input', function() {
|
|
|
|
const distance: any = $('#distance').val();
|
|
|
|
const distanceFine: any = $('#distancefine').val();
|
|
|
|
params.distance = parseFloat(distance) + parseFloat(distanceFine);
|
2020-11-24 12:53:30 +00:00
|
|
|
});
|
2020-11-24 21:12:32 +00:00
|
|
|
$('#circlesize').on('input', function() {
|
|
|
|
const circleSize: any = $('#circlesize').val();
|
|
|
|
params.circleSize = parseFloat(circleSize);
|
|
|
|
});
|
2020-11-25 17:58:49 +00:00
|
|
|
$('#instance').on('input', function() {
|
|
|
|
const instance: any = $('#instance').val();
|
|
|
|
params.instanceNumber = parseInt(instance);
|
|
|
|
});
|
2020-11-25 11:43:13 +00:00
|
|
|
$('#rotx').on('input', function() {
|
|
|
|
const rotx: any = $('#rotx').val();
|
|
|
|
params.rot.x = parseFloat(rotx);
|
|
|
|
});
|
|
|
|
$('#roty').on('input', function() {
|
|
|
|
const roty: any = $('#roty').val();
|
|
|
|
params.rot.y = parseFloat(roty);
|
|
|
|
});
|
|
|
|
$('#rotz').on('input', function() {
|
|
|
|
const rotz: any = $('#rotz').val();
|
|
|
|
params.rot.z = parseFloat(rotz);
|
|
|
|
});
|
2020-11-25 12:45:25 +00:00
|
|
|
$('#rotspeed').on('input', function() {
|
|
|
|
const rotSpeed: any = $('#rotspeed').val();
|
|
|
|
params.rotSpeed = parseFloat(rotSpeed);
|
|
|
|
});
|
2020-11-24 21:12:32 +00:00
|
|
|
$('#fov').on('input', function() {
|
|
|
|
const fov: any = $('#fov').val();
|
|
|
|
params.fov = parseFloat(fov);
|
2020-11-24 15:30:59 +00:00
|
|
|
});
|
2020-11-24 18:18:45 +00:00
|
|
|
$('#s_blackandwhite').on('click', function() {
|
2020-11-24 12:53:30 +00:00
|
|
|
[programInfo, fragmentShader] = changeFragmentShader(gl,
|
|
|
|
shaderProgram, fragmentShader, fsSource, vsSource);
|
|
|
|
});
|
2020-11-24 18:18:45 +00:00
|
|
|
$('#s_color').on('click', function() {
|
2020-11-24 12:53:30 +00:00
|
|
|
[programInfo, fragmentShader] = changeFragmentShader(gl,
|
|
|
|
shaderProgram, fragmentShader, fsSource2, vsSource);
|
|
|
|
});
|
2020-11-25 12:15:26 +00:00
|
|
|
$('#s_grey').on('click', function() {
|
2020-11-24 15:30:59 +00:00
|
|
|
[programInfo, fragmentShader] = changeFragmentShader(gl,
|
|
|
|
shaderProgram, fragmentShader, fsSource3, vsSource);
|
|
|
|
});
|
2020-11-24 18:18:45 +00:00
|
|
|
$('#s_texture').on('click', function() {
|
|
|
|
[programInfo, fragmentShader] = changeFragmentShader(gl,
|
|
|
|
shaderProgram, fragmentShader, fsSource4, vsSource);
|
|
|
|
});
|
2020-11-25 11:43:13 +00:00
|
|
|
$('#s_sobel').on('click', function() {
|
|
|
|
[programInfo, fragmentShader] = changeFragmentShader(gl,
|
|
|
|
shaderProgram, fragmentShader, fsSource5, vsSource);
|
|
|
|
});
|
2020-11-24 16:28:40 +00:00
|
|
|
$('#o_sphere').on('click', async function() {
|
2020-11-24 12:53:30 +00:00
|
|
|
const data = await getObj('/static/objs/sphere.obj');
|
2020-11-24 15:30:59 +00:00
|
|
|
updateObj(data);
|
2020-11-24 12:53:30 +00:00
|
|
|
});
|
2020-11-24 16:28:40 +00:00
|
|
|
$('#o_teapot').on('click', async function() {
|
2020-11-24 12:53:30 +00:00
|
|
|
const data = await getObj('/static/objs/teapot.obj');
|
2020-11-24 15:30:59 +00:00
|
|
|
updateObj(data);
|
|
|
|
});
|
2020-11-24 16:28:40 +00:00
|
|
|
$('#o_fox').on('click', async function() {
|
2020-11-24 15:30:59 +00:00
|
|
|
const data = await getObj('/static/objs/fox.obj');
|
|
|
|
updateObj(data);
|
2020-11-24 11:10:57 +00:00
|
|
|
});
|
2020-11-25 11:43:13 +00:00
|
|
|
$('#o_mecha').on('click', async function() {
|
|
|
|
const data = await getObj('/static/objs/mecha.obj');
|
|
|
|
updateObj(data);
|
|
|
|
});
|
|
|
|
$('#o_racer').on('click', async function() {
|
|
|
|
const data = await getObj('/static/objs/racer.obj');
|
|
|
|
updateObj(data);
|
|
|
|
});
|
2020-11-24 18:18:45 +00:00
|
|
|
$('#t_wall').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/wall.png');
|
|
|
|
});
|
|
|
|
$('#t_ice').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/ice.png');
|
|
|
|
});
|
|
|
|
$('#t_noise').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/noise.png');
|
|
|
|
});
|
|
|
|
$('#t_fox').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/fox.png');
|
|
|
|
});
|
2020-11-25 11:43:13 +00:00
|
|
|
$('#t_racer').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/racer.png');
|
|
|
|
});
|
|
|
|
$('#t_racer_wireframe').on('click', async function() {
|
|
|
|
texture = loadTexture(gl, '/static/textures/racer_wireframe.png');
|
|
|
|
});
|
2020-11-23 12:47:44 +00:00
|
|
|
});
|
2020-11-24 12:53:30 +00:00
|
|
|
requestAnimationFrame(render);
|
2020-11-22 14:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a webgl scene
|
|
|
|
* @param {any} gl the WebGL context
|
|
|
|
* @param {any} programInfo WebGL program information
|
|
|
|
* @param {any} buffers the buffers to draw
|
2020-11-23 12:47:44 +00:00
|
|
|
* @param {number} length the index buffer length
|
2020-11-24 21:12:32 +00:00
|
|
|
* @param {number} params various parameterss
|
2020-11-24 18:18:45 +00:00
|
|
|
* @param {any} texture the texture to load
|
2020-11-22 14:09:28 +00:00
|
|
|
*/
|
2020-11-23 12:47:44 +00:00
|
|
|
function drawScene(gl: any,
|
|
|
|
programInfo: any,
|
|
|
|
buffers: any,
|
2020-11-24 12:10:47 +00:00
|
|
|
length: number,
|
2020-11-24 21:12:32 +00:00
|
|
|
params: any,
|
2020-11-24 18:18:45 +00:00
|
|
|
texture: any) {
|
2020-11-22 14:09:28 +00:00
|
|
|
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
|
|
gl.clearDepth(1.0);
|
|
|
|
gl.enable(gl.DEPTH_TEST);
|
|
|
|
gl.depthFunc(gl.LEQUAL);
|
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
|
|
|
2020-11-23 19:40:51 +00:00
|
|
|
|
2020-11-22 14:09:28 +00:00
|
|
|
{
|
2020-11-22 19:56:56 +00:00
|
|
|
const numComponents = 3;
|
2020-11-22 14:09:28 +00:00
|
|
|
const type = gl.FLOAT;
|
|
|
|
const normalize = false;
|
|
|
|
const stride = 0;
|
|
|
|
const offset = 0;
|
2020-11-24 18:18:45 +00:00
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.positions);
|
2020-11-22 14:09:28 +00:00
|
|
|
gl.vertexAttribPointer(
|
|
|
|
programInfo.attribLocations.vertexPosition,
|
|
|
|
numComponents,
|
|
|
|
type,
|
|
|
|
normalize,
|
|
|
|
stride,
|
|
|
|
offset);
|
|
|
|
gl.enableVertexAttribArray(
|
|
|
|
programInfo.attribLocations.vertexPosition);
|
|
|
|
}
|
2020-11-23 16:07:53 +00:00
|
|
|
{
|
|
|
|
const numComponents = 3;
|
|
|
|
const type = gl.FLOAT;
|
|
|
|
const normalize = false;
|
|
|
|
const stride = 0;
|
|
|
|
const offset = 0;
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.normals);
|
|
|
|
gl.vertexAttribPointer(
|
|
|
|
programInfo.attribLocations.vertexNormal,
|
|
|
|
numComponents,
|
|
|
|
type,
|
|
|
|
normalize,
|
|
|
|
stride,
|
|
|
|
offset);
|
|
|
|
gl.enableVertexAttribArray(
|
|
|
|
programInfo.attribLocations.vertexNormal);
|
|
|
|
}
|
2020-11-24 18:18:45 +00:00
|
|
|
{
|
2020-11-26 08:11:02 +00:00
|
|
|
const numComponents = 2;
|
|
|
|
const type = gl.FLOAT;
|
|
|
|
const normalize = false;
|
|
|
|
const stride = 0;
|
|
|
|
const offset = 0;
|
2020-11-24 18:18:45 +00:00
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.uvs);
|
|
|
|
gl.vertexAttribPointer(programInfo.attribLocations.textureCoord,
|
2020-11-26 08:11:02 +00:00
|
|
|
numComponents,
|
2020-11-24 18:18:45 +00:00
|
|
|
type,
|
|
|
|
normalize,
|
|
|
|
stride,
|
|
|
|
offset);
|
|
|
|
gl.enableVertexAttribArray(programInfo.attribLocations.textureCoord);
|
|
|
|
}
|
|
|
|
|
2020-11-22 19:56:56 +00:00
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffers.indices);
|
2020-11-22 14:09:28 +00:00
|
|
|
gl.useProgram(programInfo.program);
|
2020-11-24 18:44:32 +00:00
|
|
|
gl.activeTexture(gl.TEXTURE0);
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
|
|
gl.uniform1i(programInfo.uniformLocations.uSampler, 0);
|
|
|
|
|
2020-11-26 08:11:02 +00:00
|
|
|
const [
|
|
|
|
projectionMatrix,
|
|
|
|
viewMatrix,
|
|
|
|
modelMatrix,
|
|
|
|
normalModelMatrix,
|
|
|
|
] = initMatrices(gl, params);
|
2020-11-25 17:58:49 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < params.instanceNumber; i++) {
|
|
|
|
gl.uniformMatrix4fv(
|
|
|
|
programInfo.uniformLocations.projectionMatrix,
|
|
|
|
false,
|
|
|
|
projectionMatrix);
|
|
|
|
gl.uniformMatrix4fv(
|
|
|
|
programInfo.uniformLocations.viewMatrix,
|
|
|
|
false,
|
|
|
|
viewMatrix);
|
|
|
|
gl.uniformMatrix4fv(
|
|
|
|
programInfo.uniformLocations.modelMatrix,
|
|
|
|
false,
|
|
|
|
modelMatrix[i]);
|
|
|
|
gl.uniformMatrix4fv(
|
|
|
|
programInfo.uniformLocations.normalModelMatrix,
|
|
|
|
false,
|
|
|
|
normalModelMatrix[i]);
|
2020-11-23 12:47:44 +00:00
|
|
|
const vertexCount = length;
|
2020-11-22 19:56:56 +00:00
|
|
|
const type = gl.UNSIGNED_SHORT;
|
|
|
|
const offset = 0;
|
|
|
|
gl.drawElements(gl.TRIANGLES, vertexCount, type, offset);
|
|
|
|
}
|
2020-11-22 14:09:28 +00:00
|
|
|
}
|