2017-10-08 03:17:36 +02:00
|
|
|
/**
|
|
|
|
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @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(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-10-08 03:17:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Mesh.Text.prototype.updateInstance = function() {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.D3.Mesh.prototype.updateInstance.call(this);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.D3.Graphics
|
|
|
|
* @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
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|