@awayjs/renderer
Version:
Renderer for AwayJS
297 lines (296 loc) • 11.4 kB
JavaScript
import { __extends } from "tslib";
import { AbstractMethodError, AssetBase } from '@awayjs/core';
import { AttributesView, Float3Attributes, Short3Attributes } from '@awayjs/stage';
import { ElementsEvent } from '../events/ElementsEvent';
/**
* @class away.base.TriangleElements
*/
var ElementsBase = /** @class */ (function (_super) {
__extends(ElementsBase, _super);
/**
*
*/
function ElementsBase(concatenatedBuffer) {
if (concatenatedBuffer === void 0) { concatenatedBuffer = null; }
var _this = _super.call(this) || this;
_this.isDynamic = false;
_this._customAttributesNames = new Array();
_this._customAttributes = new Object();
_this._autoDeriveNormals = true;
_this._autoDeriveTangents = true;
_this._boundsRequests = 0;
_this._numElements = 0;
_this._numVertices = 0;
_this._verticesDirty = new Object();
_this._invalidateVertices = new Object();
_this.usages = 0;
_this._concatenatedBuffer = concatenatedBuffer;
return _this;
}
Object.defineProperty(ElementsBase.prototype, "concatenatedBuffer", {
get: function () {
return this._concatenatedBuffer;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "indices", {
/**
* The raw index data that define the faces.
*/
get: function () {
return this._indices;
},
enumerable: false,
configurable: true
});
/**
*
*/
ElementsBase.prototype.getCustomAtributesNames = function () {
return this._customAttributesNames;
};
/**
*
*/
ElementsBase.prototype.getCustomAtributes = function (name) {
return this._customAttributes[name];
};
Object.defineProperty(ElementsBase.prototype, "numElements", {
/**
* The total amount of triangles in the TriangleElements.
*/
get: function () {
return this._numElements;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "numVertices", {
get: function () {
return this._numVertices;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "condensedIndexLookUp", {
get: function () {
return this._condensedIndexLookUp;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "autoDeriveNormals", {
/**
* True if the vertex normals should be derived from the geometry, false if the vertex normals are set
* explicitly.
*/
get: function () {
return this._autoDeriveNormals;
},
set: function (value) {
if (this._autoDeriveNormals == value)
return;
this._autoDeriveNormals = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "autoDeriveTangents", {
/**
* True if the vertex tangents should be derived from the geometry, false if the vertex normals are set
* explicitly.
*/
get: function () {
return this._autoDeriveTangents;
},
set: function (value) {
if (this._autoDeriveTangents == value)
return;
this._autoDeriveTangents = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ElementsBase.prototype, "useCondensedIndices", {
/**
* Offers the option of enabling GPU accelerated animation on skeletons larger than 32 joints
* by condensing the number of joint index values required per sprite. Only applicable to
* skeleton animations that utilise more than one sprite object. Defaults to false.
*/
get: function () {
return this._useCondensedIndices;
},
set: function (value) {
if (this._useCondensedIndices == value)
return;
this._useCondensedIndices = value;
},
enumerable: false,
configurable: true
});
ElementsBase.prototype.copyTo = function (elements) {
if (this.indices)
elements.setIndices(this.indices.clone());
for (var name_1 in this._customAttributes)
elements.setCustomAttributes(name_1, this.getCustomAtributes(name_1).clone());
};
/**
*
*/
ElementsBase.prototype.dispose = function () {
this.clear();
this._boundsRequests = 0;
if (this._convexHull) {
this._convexHull.dispose();
this._convexHull = null;
}
if (this._indices) {
this._indices.dispose();
this._indices = null;
}
for (var name_2 in this._customAttributes) {
this._customAttributes[name_2].dispose();
delete this._customAttributes;
}
};
ElementsBase.prototype.setIndices = function (values, offset) {
if (offset === void 0) { offset = 0; }
if (values instanceof Short3Attributes) {
if (this._indices)
this.clearIndices();
this._indices = values;
}
else if (values) {
if (!this._indices)
this._indices = new Short3Attributes();
this._indices.set(values, offset);
}
else if (this._indices) {
this._indices.dispose();
this._indices = null;
this.clearIndices();
}
if (this._indices) {
this._numElements = this._indices.count;
this.invalidateIndices();
}
else {
this._numElements = 0;
}
};
ElementsBase.prototype.setCustomAttributes = function (name, values, offset) {
if (offset === void 0) { offset = 0; }
if (values == this._customAttributes[name])
return;
if (values instanceof AttributesView) {
this.clearVertices(this._customAttributes[name]);
this._customAttributes[name] = values;
}
else if (values) {
if (!this._customAttributes[name]) {
//default custom atrributes is Float3
this._customAttributes[name] = new Float3Attributes(this._concatenatedBuffer);
}
this._customAttributes[name].set(values, offset);
}
else if (this._customAttributes[name]) {
this.clearVertices(this._customAttributes[name]);
this._customAttributesNames.splice(this._customAttributesNames.indexOf(name), 1);
delete this._customAttributes[name];
return;
}
this.invalidateVertices(this._customAttributes[name]);
this._verticesDirty[this._customAttributes[name].id] = false;
if (this._customAttributesNames.indexOf(name) == -1)
this._customAttributesNames.push(name);
};
ElementsBase.prototype.updateScale9 = function (targetScaleX, targetScaleY) {
throw new AbstractMethodError('UpdateScale9 MUST be overridden by subclass');
};
ElementsBase.prototype.prepareScale9 = function (bounds, grid, clone, emitUV, uvMatrix) {
throw new AbstractMethodError('prepareScale9 MUST be overridden by subclass');
};
/**
* Clones the current object
* @return An exact duplicate of the current object.
*/
ElementsBase.prototype.clone = function () {
throw new AbstractMethodError();
};
ElementsBase.prototype.applyTransformation = function (transform, count, offset) {
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
/**
* Scales the geometry.
* @param scale The amount by which to scale.
*/
ElementsBase.prototype.scale = function (scale, count, offset) {
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
ElementsBase.prototype.scaleUV = function (scaleU, scaleV, count, offset) {
if (scaleU === void 0) { scaleU = 1; }
if (scaleV === void 0) { scaleV = 1; }
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
ElementsBase.prototype.getBoxBounds = function (node, strokeFlag, matrix3D, cache, target, count, offset) {
if (node === void 0) { node = null; }
if (strokeFlag === void 0) { strokeFlag = true; }
if (matrix3D === void 0) { matrix3D = null; }
if (cache === void 0) { cache = null; }
if (target === void 0) { target = null; }
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
ElementsBase.prototype.getSphereBounds = function (center, matrix3D, strokeFlag, cache, target, count, offset) {
if (matrix3D === void 0) { matrix3D = null; }
if (strokeFlag === void 0) { strokeFlag = true; }
if (cache === void 0) { cache = null; }
if (target === void 0) { target = null; }
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
ElementsBase.prototype.hitTestPoint = function (node, x, y, z, box, count, offset) {
if (count === void 0) { count = 0; }
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
ElementsBase.prototype.invalidateIndices = function () {
if (!this._invalidateIndices)
this._invalidateIndices = new ElementsEvent(ElementsEvent.INVALIDATE_INDICES, this._indices);
this.dispatchEvent(this._invalidateIndices);
};
ElementsBase.prototype.clearIndices = function () {
this.dispatchEvent(new ElementsEvent(ElementsEvent.CLEAR_INDICES, this._indices));
};
ElementsBase.prototype.invalidateVertices = function (attributesView) {
if (!attributesView || this._verticesDirty[attributesView.id])
return;
this._verticesDirty[attributesView.id] = true;
if (!this._invalidateVertices[attributesView.id])
this._invalidateVertices[attributesView.id] = new ElementsEvent(ElementsEvent.INVALIDATE_VERTICES, attributesView);
this.dispatchEvent(this._invalidateVertices[attributesView.id]);
};
ElementsBase.prototype.clearVertices = function (attributesView) {
if (!attributesView)
return;
attributesView.dispose();
this.dispatchEvent(new ElementsEvent(ElementsEvent.CLEAR_VERTICES, attributesView));
this._verticesDirty[attributesView.id] = null;
this._invalidateVertices[attributesView.id] = null;
};
ElementsBase.prototype.testCollision = function (collision, box, closestFlag, material, count, offset) {
if (offset === void 0) { offset = 0; }
throw new AbstractMethodError();
};
return ElementsBase;
}(AssetBase));
export { ElementsBase };