r3-legacy/src/game-lib-d3-mesh-text.js

228 lines
6.6 KiB
JavaScript
Raw Normal View History

/**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
* @param graphics GameLib.GraphicsRuntime
* @param apiMesh GameLib.D3.API.Mesh
* @param font
* @param size
* @param height
* @param curveSegments
* @param bevelEnabled
* @param bevelThickness
* @param bevelSize
* @param bevelSegments
* @param text
* @constructor
*/
GameLib.D3.Mesh.Text = function (
graphics,
apiMesh,
text,
font,
size,
height,
curveSegments,
bevelEnabled,
bevelThickness,
bevelSize,
bevelSegments
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
2017-12-04 13:23:15 +01:00
apiMesh = {
meshType : GameLib.D3.API.Mesh.MESH_TYPE_TEXT
};
}
2017-12-04 13:23:15 +01:00
if (apiMesh instanceof GameLib.D3.Mesh.Text) {
return apiMesh;
}
if (GameLib.Utils.UndefinedOrNull(text)) {
text = '-=<yb4f310';
}
this.text = text;
if (GameLib.Utils.UndefinedOrNull(font)) {
font = new GameLib.D3.Font(
this.graphics
);
}
this.font = font;
if (GameLib.Utils.UndefinedOrNull(size)) {
size = 100;
}
this.size = size;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 50;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(curveSegments)) {
curveSegments = 12;
}
this.curveSegments = curveSegments;
if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) {
bevelEnabled = false;
}
this.bevelEnabled = bevelEnabled;
if (GameLib.Utils.UndefinedOrNull(bevelThickness)) {
bevelThickness = 10;
}
this.bevelThickness = bevelThickness;
if (GameLib.Utils.UndefinedOrNull(bevelSize)) {
bevelSize = 8;
}
this.bevelSize = bevelSize;
if (GameLib.Utils.UndefinedOrNull(bevelSegments)) {
bevelSegments = 3;
}
this.bevelSegments = bevelSegments;
GameLib.D3.Mesh.call(
this,
this.graphics,
apiMesh
);
};
GameLib.D3.Mesh.Text.prototype = Object.create(GameLib.D3.Mesh.prototype);
GameLib.D3.Mesh.Text.prototype.constructor = GameLib.D3.Mesh.Text;
GameLib.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);
}
2017-10-23 14:52:35 +02:00
GameLib.D3.Mesh.prototype.createInstance.call(this);
this.instance.userData.font = this.font;
this.instance.userData.size = this.size;
this.instance.userData.height = this.height;
this.instance.userData.curveSegments = this.curveSegments;
this.instance.userData.bevelEnabled = this.bevelEnabled;
this.instance.userData.bevelThickness = this.bevelThickness;
this.instance.userData.bevelSize = this.bevelSize;
this.instance.userData.bevelSegments = this.bevelSegments;
};
2017-11-13 15:06:59 +01:00
GameLib.D3.Mesh.Text.prototype.updateInstance = function(property) {
if (
this.instance.userData.text !== this.text ||
this.instance.userData.font !== this.font ||
this.instance.userData.size !== this.size ||
this.instance.userData.height !== this.height ||
this.instance.userData.curveSegments !== this.curveSegments ||
this.instance.userData.bevelEnabled !== this.bevelEnabled ||
this.instance.userData.bevelThickness !== this.bevelThickness ||
this.instance.userData.bevelSize !== this.bevelSize ||
this.instance.userData.bevelSegments !== this.bevelSegments
) {
this.instance.userData.text = this.text;
this.instance.userData.font = this.font;
this.instance.userData.size = this.size;
this.instance.userData.height = this.height;
this.instance.userData.curveSegments = this.curveSegments;
this.instance.userData.bevelEnabled = this.bevelEnabled;
this.instance.userData.bevelThickness = this.bevelThickness;
this.instance.userData.bevelSize = this.bevelSize;
this.instance.userData.bevelSegments = this.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;
}
2017-11-13 15:06:59 +01:00
GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
* @returns {GameLib.D3.API.Mesh}
*/
GameLib.D3.Mesh.Text.prototype.toApiObject = function() {
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
apiMesh.text = this.text;
apiMesh.font = GameLib.Utils.IdOrNull(this.font);
apiMesh.size = this.size;
apiMesh.height = this.height;
apiMesh.curveSegments = this.curveSegments;
apiMesh.bevelEnabled = this.bevelEnabled;
apiMesh.bevelThickness = this.bevelThickness;
apiMesh.bevelSize = this.bevelSize;
apiMesh.bevelSegments = this.bevelSegments;
return apiMesh;
};
/**
* Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.GraphicsRuntime
* @param objectMesh {Object}
* @constructor
*/
GameLib.D3.Mesh.Text.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
return new GameLib.D3.Mesh.Text(
graphics,
apiMesh,
objectMesh.text,
objectMesh.font,
objectMesh.size,
objectMesh.height,
objectMesh.curveSegments,
objectMesh.bevelEnabled,
objectMesh.bevelThickness,
objectMesh.bevelSize,
objectMesh.bevelSegments
);
};