131 lines
3.3 KiB
JavaScript
131 lines
3.3 KiB
JavaScript
/**
|
|
* R3.D3.Face.Graphics
|
|
* @param apiComponent
|
|
* @constructor
|
|
*/
|
|
R3.D3.Face.Graphics = function(
|
|
apiComponent
|
|
) {
|
|
|
|
__RUNTIME_COMPONENT__;
|
|
|
|
R3.D3.Face.call(
|
|
this,
|
|
apiComponent,
|
|
true
|
|
);
|
|
|
|
};
|
|
|
|
R3.D3.Face.Graphics.prototype = Object.create(R3.D3.Face.prototype);
|
|
R3.D3.Face.Graphics.prototype.constructor = R3.D3.Face.Graphics;
|
|
|
|
R3.D3.Face.Graphics.prototype.createInstance = function() {
|
|
|
|
this.instance = this.graphics.Face(
|
|
this.v0index,
|
|
this.v1index,
|
|
this.v2index,
|
|
this.normal,
|
|
this.color,
|
|
this.materialIndex,
|
|
this.vertexColors
|
|
);
|
|
|
|
__CREATE_INSTANCE__;
|
|
};
|
|
|
|
R3.D3.Face.Graphics.prototype.updateInstance = function(property) {
|
|
|
|
if (property === 'materialIndex') {
|
|
this.instance.materialIndex = this.materialIndex;
|
|
this.parent.instance.groupsNeedUpdate = true;
|
|
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;
|
|
this.parent.instance.uvsNeedUpdate = true;
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (property === 'vertexColors') {
|
|
this.instance.vertexColors = this.vertexColors.reduce(
|
|
function(result, vertexColor) {
|
|
result.push(
|
|
this.graphics.Color(
|
|
vertexColor.r,
|
|
vertexColor.g,
|
|
vertexColor.b
|
|
)
|
|
);
|
|
return result;
|
|
}.bind(this),
|
|
[]
|
|
);
|
|
return;
|
|
}
|
|
|
|
R3.D3.Face.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
|
|
R3.D3.Face.Graphics.prototype.createHelper = function() {
|
|
|
|
console.warn('todo: createHelper needs work');
|
|
return;
|
|
|
|
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
|
|
}
|
|
},
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
R3.D3.Face.Graphics.prototype.removeHelper = function() {
|
|
|
|
console.warn('todo: removeHelper needs work');
|
|
return;
|
|
|
|
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');
|
|
|
|
}; |