MorphTarget Issue r119
comare
by Gregg Tavares
HTML
<canvas id="c"></canvas>
CSS
body {
background: #444;
color: #DDD;
}
pre {
margin: 0;
}
JavaScript
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r119/build/three.module.js';
{
const arrayBufferMap = new Map();
let currentArrayBufferInfo;
const bufNames = [
'0target (position)',
'normal',
'uv',
'color0 (color)',
'1target (position)',
'2target (position)',
'3target (position)',
'color1 (morphColor1)',
];
function glEnumToString(gl, value) {
const keys = [];
for (const key in gl) {
if (gl[key] === value) {
keys.push(key);
}
}
return keys.length ? keys.join(' | ') : `0x${value.toString(16)}`;
}
function wrapBindBuffer(origFn) {
return function(target, buffer) {
origFn.call(this, target, buffer);
if (target === this.ARRAY_BUFFER) {
if (!arrayBufferMap.has(buffer)) {
arrayBufferMap.set(buffer, {id: bufNames[arrayBufferMap.size] || arrayBufferMap.size});
}
currentArrayBufferInfo = arrayBufferMap.get(buffer);
log('bindBuffer:', currentArrayBufferInfo.id);
}
};
}
WebGL2RenderingContext.prototype.bindBuffer = wrapBindBuffer(WebGL2RenderingContext.prototype.bindBuffer);
WebGLRenderingContext.prototype.bindBuffer = wrapBindBuffer(WebGLRenderingContext.prototype.bindBuffer);
function getAttributeName(gl, index) {
const program = gl.getParameter(gl.CURRENT_PROGRAM);
const numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
for (let ii = 0; ii < numAttribs; ++ii) {
const attribInfo = gl.getActiveAttrib(program, ii);
const ndx = gl.getAttribLocation(program, attribInfo.name);
if (ndx === index) {
return attribInfo.name;
}
}
return `*unknown*(index=${index})`;
}
function warpVertexAttribPointer(origFn) {
return function(index, size, type, norm, stride, offset) {
origFn.call(this, index, size, type, norm, stride, offset);
log('vertexAttribPointer: ', getAttributeName(this, index), size,...