143 lines
3.7 KiB
JavaScript
143 lines
3.7 KiB
JavaScript
|
/**
|
||
|
* R3.D3.Geometry.Buffer.Text
|
||
|
* @param graphics R3.GraphicsRuntime
|
||
|
* @param apiGeometryBufferText
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.Geometry.Buffer.Text = function(
|
||
|
graphics,
|
||
|
apiGeometryBufferText
|
||
|
) {
|
||
|
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiGeometryBufferText)) {
|
||
|
apiGeometryBufferText = {
|
||
|
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT
|
||
|
};
|
||
|
}
|
||
|
|
||
|
R3.D3.API.Geometry.Buffer.Text.call(
|
||
|
this,
|
||
|
apiGeometryBufferText,
|
||
|
apiGeometryBufferText.text,
|
||
|
apiGeometryBufferText.font,
|
||
|
apiGeometryBufferText.size,
|
||
|
apiGeometryBufferText.height,
|
||
|
apiGeometryBufferText.curveSegments,
|
||
|
apiGeometryBufferText.bevelEnabled,
|
||
|
apiGeometryBufferText.bevelThickness,
|
||
|
apiGeometryBufferText.bevelSize,
|
||
|
apiGeometryBufferText.bevelSegments
|
||
|
);
|
||
|
|
||
|
R3.D3.Geometry.Buffer.call(
|
||
|
this,
|
||
|
this.graphics,
|
||
|
apiGeometryBufferText
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
R3.D3.Geometry.Buffer.Text.prototype = Object.create(R3.D3.Geometry.Buffer.prototype);
|
||
|
R3.D3.Geometry.Buffer.Text.prototype.constructor = R3.D3.Geometry.Buffer.Text;
|
||
|
|
||
|
/**
|
||
|
* Creates a light instance
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
R3.D3.Geometry.Buffer.Text.prototype.createInstance = function() {
|
||
|
|
||
|
if (!this.font || !this.font.instance) {
|
||
|
console.warn('font not ready for this instance');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this.instance = new THREE.TextBufferGeometry(
|
||
|
this.text,
|
||
|
{
|
||
|
font : this.font.instance,
|
||
|
size : this.size,
|
||
|
curveSegments : this.curveSegments,
|
||
|
steps : this.steps,
|
||
|
amount : this.amount,
|
||
|
bevelEnabled : this.bevelEnabled,
|
||
|
bevelThickness : this.bevelThickness,
|
||
|
bevelSize : this.bevelSize,
|
||
|
bevelSegments : this.bevelSegments
|
||
|
}
|
||
|
);
|
||
|
|
||
|
this.computeVertexNormals();
|
||
|
|
||
|
R3.D3.Geometry.Buffer.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
R3.D3.Geometry.Buffer.Text.prototype.updateInstance = function(property) {
|
||
|
|
||
|
if (
|
||
|
property === 'text' ||
|
||
|
property === 'font' ||
|
||
|
property === 'size' ||
|
||
|
property === 'height' ||
|
||
|
property === 'curveSegments' ||
|
||
|
property === 'bevelEnabled' ||
|
||
|
property === 'bevelThickness' ||
|
||
|
property === 'bevelSize' ||
|
||
|
property === 'bevelSegments'
|
||
|
) {
|
||
|
|
||
|
/**
|
||
|
* Could be that the instance does not exist - because font was not ready
|
||
|
*/
|
||
|
if (this.instance) {
|
||
|
this.instance.dispose();
|
||
|
}
|
||
|
|
||
|
this.createInstance();
|
||
|
|
||
|
if (this.parentMesh && this.parentMesh.instance) {
|
||
|
this.parentMesh.instance.geometry = this.instance;
|
||
|
|
||
|
if (this.parentMesh.helper) {
|
||
|
this.parentMesh.removeHelper();
|
||
|
this.parentMesh.createHelper();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
console.warn('do other properties here');
|
||
|
|
||
|
R3.D3.Geometry.Buffer.prototype.updateInstance.call(this, property);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a R3.D3.Geometry.Buffer.Text to a R3.D3.API.Geometry.Buffer.Text
|
||
|
* @returns {R3.D3.API.Geometry.Buffer}
|
||
|
*/
|
||
|
R3.D3.Geometry.Buffer.Text.prototype.toApiObject = function() {
|
||
|
|
||
|
var apiBufferGeometry = R3.D3.Geometry.Buffer.prototype.toApiObject.call(this);
|
||
|
|
||
|
var apiGeometryBufferText = new R3.D3.API.Geometry.Buffer.Text(
|
||
|
apiBufferGeometry,
|
||
|
this.text,
|
||
|
R3.Utils.IdOrNull(this.font),
|
||
|
this.size,
|
||
|
this.height,
|
||
|
this.curveSegments,
|
||
|
this.bevelEnabled,
|
||
|
this.bevelThickness,
|
||
|
this.bevelSize,
|
||
|
this.bevelSegments
|
||
|
);
|
||
|
|
||
|
return apiGeometryBufferText;
|
||
|
};
|