r3-legacy/bak/r3-d3-mesh-text.js

141 lines
3.4 KiB
JavaScript

/**
* R3.D3.Mesh.Text
* @param graphics R3.GraphicsRuntime
* @param apiMeshText
* @constructor
*/
R3.D3.Mesh.Text = function (
graphics,
apiMeshText
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiMeshText)) {
apiMeshText = {
meshType : R3.D3.API.Mesh.MESH_TYPE_TEXT
};
}
R3.D3.API.Mesh.Text.call(
this,
apiMeshText,
apiMeshText.text,
apiMeshText.font,
apiMeshText.size,
apiMeshText.height,
apiMeshText.curveSegments,
apiMeshText.bevelEnabled,
apiMeshText.bevelThickness,
apiMeshText.bevelSize,
apiMeshText.bevelSegments
);
if (this.font instanceof R3.D3.API.Font) {
this.font = new R3.D3.Font(
this.graphics,
this.font
)
}
R3.D3.Mesh.call(
this,
this.graphics,
this
);
};
R3.D3.Mesh.Text.prototype = Object.create(R3.D3.Mesh.prototype);
R3.D3.Mesh.Text.prototype.constructor = R3.D3.Mesh.Text;
R3.D3.Mesh.Text.prototype.createInstance = function() {
var geometry = null;
if (this.vertices.length === 0) {
geometry = new THREE.TextGeometry(
this.text,
{
font: this.font.instance,
size: this.size,
height: this.height,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelSegments: this.bevelSegments
}
);
this.updateVerticesFromGeometryInstance(geometry);
}
R3.D3.Mesh.prototype.createInstance.call(this);
};
R3.D3.Mesh.Text.prototype.updateInstance = function(property) {
if (
property === 'text' ||
property === 'font' ||
property === 'size' ||
property === 'height' ||
property === 'curveSegments' ||
property === 'bevelEnabled' ||
property === 'bevelThickness' ||
property === 'bevelSize' ||
property === 'bevelSegments'
) {
var geometry = new THREE.TextGeometry(
this.text,
{
font: this.font.instance,
size: this.size,
height: this.height,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelSegments: this.bevelSegments
}
);
this.updateVerticesFromGeometryInstance(geometry);
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
return;
}
R3.D3.Mesh.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Mesh.Text to a R3.D3.API.Mesh.Text
* @returns {R3.D3.API.Mesh.Text}
*/
R3.D3.Mesh.Text.prototype.toApiObject = function() {
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
var apiMeshText = new R3.D3.API.Mesh.Text(
apiMesh,
this.text,
this.font,
this.size,
this.height,
this.curveSegments,
this.bevelEnabled,
this.bevelThickness,
this.bevelSize,
this.bevelSegments
);
return apiMeshText;
};