r3-legacy/src/r3-d3-face-graphics.js

131 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-08-07 05:17:41 +02:00
/**
2019-08-10 19:48:08 +02:00
* R3.D3.Face.Graphics
2019-08-07 05:17:41 +02:00
* @param apiComponent
* @constructor
*/
R3.D3.Face.Graphics = function(
apiComponent
) {
2019-10-06 21:11:18 +02:00
__RUNTIME_COMPONENT__;
2019-08-10 19:48:08 +02:00
R3.D3.Face.call(
this,
apiComponent,
2019-10-06 21:11:18 +02:00
true
2019-08-07 05:17:41 +02:00
);
};
R3.D3.Face.Graphics.prototype = Object.create(R3.D3.Face.prototype);
R3.D3.Face.Graphics.prototype.constructor = R3.D3.Face.Graphics;
2019-08-10 19:48:08 +02:00
R3.D3.Face.Graphics.prototype.createInstance = function() {
2019-08-07 05:17:41 +02:00
2019-08-10 19:48:08 +02:00
this.instance = this.graphics.Face(
2019-08-07 05:17:41 +02:00
this.v0index,
this.v1index,
2019-08-10 19:48:08 +02:00
this.v2index,
this.normal,
this.color,
this.materialIndex,
this.vertexColors
2019-08-07 05:17:41 +02:00
);
2019-10-06 21:11:18 +02:00
__CREATE_INSTANCE__;
2019-08-07 05:17:41 +02:00
};
2019-08-10 19:48:08 +02:00
R3.D3.Face.Graphics.prototype.updateInstance = function(property) {
2019-08-07 05:17:41 +02:00
if (property === 'materialIndex') {
this.instance.materialIndex = this.materialIndex;
2019-08-10 19:48:08 +02:00
this.parent.instance.groupsNeedUpdate = true;
2019-08-07 05:17:41 +02:00
return;
}
if (property === 'uvs') {
this.uvs[uvSet][uvIndex].instance.x = this.uvs[uvSet][uvIndex].x;
this.uvs[uvSet][uvIndex].instance.y = this.uvs[uvSet][uvIndex].y;
2019-08-10 19:48:08 +02:00
this.parent.instance.uvsNeedUpdate = true;
2019-08-07 05:17:41 +02:00
return;
}
2019-08-10 19:48:08 +02:00
if (property === 'color') {
this.instance.color.r = this.color.r;
this.instance.color.g = this.color.g;
this.instance.color.b = this.color.b;
return;
}
2019-08-07 05:17:41 +02:00
2019-08-10 19:48:08 +02:00
if (property === 'vertexColors') {
this.instance.vertexColors = this.vertexColors.reduce(
function(result, vertexColor) {
result.push(
this.graphics.Color(
vertexColor.r,
vertexColor.g,
vertexColor.b
)
2019-08-07 05:17:41 +02:00
);
return result;
}.bind(this),
[]
2019-08-10 19:48:08 +02:00
);
return;
}
R3.D3.Face.prototype.updateInstance.call(this, property);
2019-08-07 05:17:41 +02:00
};
2019-08-10 19:48:08 +02:00
R3.D3.Face.Graphics.prototype.createHelper = function() {
console.warn('todo: createHelper needs work');
return;
2019-08-07 05:17:41 +02:00
this.backupProperties = {
color : {
r: this.color.r,
g: this.color.g,
b: this.color.b
},
material : {
emissive : {
r: mesh.materials[this.materialIndex].emissive.r,
g: mesh.materials[this.materialIndex].emissive.g,
b: mesh.materials[this.materialIndex].emissive.b
}
},
2019-08-10 19:48:08 +02:00
2019-08-07 05:17:41 +02:00
vertexColors : mesh.materials[this.materialIndex].vertexColors
};
this.instance.vertexColors = [
new THREE.Color(1,0,0),
new THREE.Color(0,1,0),
new THREE.Color(0,0,1)
];
mesh.materials[this.materialIndex].vertexColors = R3.D3.API.Material.TYPE_VERTEX_COLORS;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
mesh.instance.geometry.elementsNeedUpdate = true;
};
2019-08-10 19:48:08 +02:00
R3.D3.Face.Graphics.prototype.removeHelper = function() {
console.warn('todo: removeHelper needs work');
return;
2019-08-07 05:17:41 +02:00
this.instance.color.r = this.backupProperties.color.r;
this.instance.color.g = this.backupProperties.color.g;
this.instance.color.b = this.backupProperties.color.b;
mesh.instance.geometry.colorsNeedUpdate = true;
mesh.materials[this.materialIndex].vertexColors = this.backupProperties.vertexColors;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
};