@awayjs/scene
Version:
AwayJS scene classes
76 lines (75 loc) • 2.35 kB
JavaScript
var TextShape = /** @class */ (function () {
function TextShape(format, cacheId) {
this.format = format;
this.cacheId = cacheId;
this.verts = [];
this.uvs = [];
this._length = 0;
this.verts = [];
this.uvs = [];
}
Object.defineProperty(TextShape.prototype, "length", {
get: function () {
return this._length;
},
set: function (val) {
if (val > this._length) {
return;
}
var verts = this.verts;
var uvs = this.uvs;
if (val === 0) {
this._length = 0;
verts.length = 0;
uvs.length = 0;
return;
}
var index = 0;
var size = val;
while (index < verts.length && size > 0) {
size -= verts[index].length;
index++;
}
if (size < 0) {
// resize buffer
verts[index - 1] = verts[index - 1].subarray(0, size + verts[index - 1].length);
if (uvs[index - 1]) {
uvs[index - 1] = uvs[index - 1].subarray(0, size + uvs[index - 1].length);
}
}
verts.length = index;
this._length = val;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TextShape.prototype, "hasUV", {
get: function () {
return this.uvs.length > 0;
},
enumerable: false,
configurable: true
});
TextShape.prototype.addChunk = function (buffer, uvs) {
if (this.verts.length !== this.uvs.length && uvs) {
throw 'You can\'t mix TextShape with UV and without in same place';
}
if (uvs && buffer.length !== uvs.length) {
throw 'Position buffer and UV buffer should has equal size';
}
this._length += buffer.length;
this.verts.push(buffer);
if (uvs) {
this.uvs.push(uvs);
}
};
Object.defineProperty(TextShape.prototype, "tall", {
get: function () {
return this.verts[this.verts.length - 1];
},
enumerable: false,
configurable: true
});
return TextShape;
}());
export { TextShape };