UNPKG

@awayjs/renderer

Version:
804 lines (803 loc) 34.1 kB
import { __extends } from "tslib"; import { Matrix3D, Vector3D, Point } from '@awayjs/core'; import { AttributesView, Float3Attributes, Float2Attributes, } from '@awayjs/stage'; import { ElementsUtils } from '../utils/ElementsUtils'; import { TriangleElementsUtils } from '../utils/TriangleElementsUtils'; import { ConvexHullUtils } from '../utils/ConvexHullUtils'; import { ElementsBase } from './ElementsBase'; var MIN_COEFF = 1 / 10000000; /** * @class away.base.TriangleElements */ var TriangleElements = /** @class */ (function (_super) { __extends(TriangleElements, _super); function TriangleElements() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._faceNormalsDirty = true; _this._faceTangentsDirty = true; //used for hittesting geometry _this.hitTestCache = new Object(); return _this; } Object.defineProperty(TriangleElements.prototype, "assetType", { get: function () { return TriangleElements.assetType; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "jointsPerVertex", { /** * */ get: function () { return this._jointsPerVertex; }, set: function (value) { if (this._jointsPerVertex == value) return; this._jointsPerVertex = value; if (this._jointIndices) this._jointIndices.dimensions = this._jointsPerVertex; if (this._jointWeights) this._jointWeights.dimensions = this._jointsPerVertex; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "positions", { /** * */ get: function () { if (!this._positions) this.setPositions(new Float3Attributes(this._concatenatedBuffer)); return this._positions; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "normals", { /** * */ get: function () { if (!this._normals || this._verticesDirty[this._normals.id]) this.setNormals(this._normals); return this._normals; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "tangents", { /** * */ get: function () { if (!this._tangents || this._verticesDirty[this._tangents.id]) this.setTangents(this._tangents); return this._tangents; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "faceNormals", { /** * The raw data of the face normals, in the same order as the faces are listed in the index list. */ get: function () { if (this._faceNormalsDirty) this.updateFaceNormals(); return this._faceNormals; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "faceTangents", { /** * The raw data of the face tangets, in the same order as the faces are listed in the index list. */ get: function () { if (this._faceTangentsDirty) this.updateFaceTangents(); return this._faceTangents; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "uvs", { /** * */ get: function () { if (!this._uvs && TriangleElements.isIE) { var attributesView2 = new AttributesView(Float32Array, 2); attributesView2.set(this._positions.get(this._positions.count)); var attributesBuffer2 = attributesView2.attributesBuffer; this._uvs = new Float2Attributes(attributesBuffer2); attributesView2.dispose(); } return this._uvs; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "jointIndices", { /** * */ get: function () { return this._jointIndices; }, enumerable: false, configurable: true }); Object.defineProperty(TriangleElements.prototype, "jointWeights", { /** * */ get: function () { return this._jointWeights; }, enumerable: false, configurable: true }); TriangleElements.prototype.prepareScale9 = function (bounds, grid, clone, emitUV, uvMatrix) { return TriangleElementsUtils.prepareScale9(this, bounds, grid, clone, emitUV, uvMatrix); }; TriangleElements.prototype.updateScale9 = function (scaleX, scaleY) { if (!this.scale9Indices) { return; } TriangleElementsUtils.updateScale9(this, this.originalScale9Bounds, scaleX, scaleY, false, false); }; TriangleElements.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; } count = count || this._numElements || this._numVertices; this._boundsRequests++; if (Settings.ENABLE_CONVEX_BOUNDS && this._boundsRequests > Settings.CONVEX_MIN_REQUIEST_FOR_BUILD && count > Settings.POINTS_COUNT_FOR_CONVEX && !this.isDynamic // diable for dynamic elements, beacause a reconstructed every frame ) { if (!this._convexHull || this._convexHull.count !== count // drop hull data, invalid || this._convexHull.offset !== offset // drop hull data, invalid ) { this._convexHull = ConvexHullUtils.fromAttribute(this.positions, this.indices, 1, // step every index count, offset); if (this._convexHull) { this._convexHull.offset = offset; this._convexHull.count = count; console.debug('[Triangle] Build convex for:', this.id, 'vertex / hull', (count / this._convexHull.points.length) | 0); } } // Crashable?? // Maybe, i don't know, falling back to utils if (this._convexHull) { return ConvexHullUtils.createBox(this._convexHull, matrix3D, target, cache); } } return TriangleElementsUtils.getBoxBounds(this.positions, this.indices, matrix3D, cache, target, count, offset); }; TriangleElements.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; } return TriangleElementsUtils.getSphereBounds(this.positions, center, matrix3D, cache, target, count || this._numVertices, offset); }; TriangleElements.prototype.hitTestPoint = function (node, x, y, z, box, count, offset, idx_count, idx_offset) { if (count === void 0) { count = 0; } if (offset === void 0) { offset = 0; } if (idx_count === void 0) { idx_count = 0; } if (idx_offset === void 0) { idx_offset = 0; } return TriangleElementsUtils.hitTest(x, y, 0, box, this, count || this._numElements || this._numVertices, offset); }; TriangleElements.prototype.setPositions = function (values, offset) { if (offset === void 0) { offset = 0; } if (values == this._positions) return; if (values instanceof AttributesView) { this.clearVertices(this._positions); this._positions = values; } else if (values) { if (!this._positions) this._positions = new Float3Attributes(this._concatenatedBuffer); this._positions.set(values, offset); } else { this.clearVertices(this._positions); this._positions = new Float3Attributes(this._concatenatedBuffer); //positions cannot be null } this._numVertices = this._positions.count; if (this._autoDeriveNormals) this.invalidateVertices(this._normals); if (this._autoDeriveTangents) this.invalidateVertices(this._tangents); this.invalidateVertices(this._positions); this._verticesDirty[this._positions.id] = false; // drop hull, positions is should be reconstructed this._convexHull = null; }; TriangleElements.prototype.setNormals = function (values, offset) { if (offset === void 0) { offset = 0; } if (!this._autoDeriveNormals) { if (values == this._normals) return; if (values instanceof Float3Attributes) { this.clearVertices(this._normals); this._normals = values; } else if (values) { if (!this._normals) this._normals = new Float3Attributes(this._concatenatedBuffer); this._normals.set(values, offset); } else if (this._normals) { this.clearVertices(this._normals); this._normals = null; return; } } else { this._normals = ElementsUtils.generateNormals(this.indices, this.faceNormals, this._normals, this._concatenatedBuffer); } this.invalidateVertices(this._normals); this._verticesDirty[this._normals.id] = false; }; TriangleElements.prototype.setTangents = function (values, offset) { if (offset === void 0) { offset = 0; } if (!this._autoDeriveTangents) { if (values == this._tangents) return; if (values instanceof Float3Attributes) { this.clearVertices(this._tangents); this._tangents = values; } else if (values) { if (!this._tangents) this._tangents = new Float3Attributes(this._concatenatedBuffer); this._tangents.set(values, offset); } else if (this._tangents) { this.clearVertices(this._tangents); this._tangents = null; return; } } else { this._tangents = ElementsUtils.generateTangents(this.indices, this.faceTangents, this.faceNormals, this._tangents, this._concatenatedBuffer); } this.invalidateVertices(this._tangents); this._verticesDirty[this._tangents.id] = false; }; TriangleElements.prototype.setUVs = function (values, offset) { if (offset === void 0) { offset = 0; } if (values == this._uvs) return; if (values instanceof AttributesView) { this.clearVertices(this._uvs); this._uvs = values; } else if (values) { if (!this._uvs) this._uvs = new Float2Attributes(this._concatenatedBuffer); this._uvs.set(values, offset); } else if (this._uvs) { this.clearVertices(this._uvs); this._uvs = null; return; } this.invalidateVertices(this._uvs); this._verticesDirty[this._uvs.id] = false; }; TriangleElements.prototype.setJointIndices = function (values, offset) { if (offset === void 0) { offset = 0; } if (values == this._jointIndices) return; if (values instanceof AttributesView) { this.clearVertices(this._jointIndices); this._jointIndices = values; } else if (values) { if (!this._jointIndices) this._jointIndices = new AttributesView(Float32Array, this._jointsPerVertex, this._concatenatedBuffer); if (this._useCondensedIndices) { var i = 0; var oldIndex = void 0; var newIndex = 0; var dic = new Object(); this._condensedIndexLookUp = new Array(); while (i < values.length) { oldIndex = values[i]; // if we encounter a new index, assign it a new condensed index if (dic[oldIndex] == undefined) { dic[oldIndex] = newIndex; this._condensedIndexLookUp[newIndex++] = oldIndex; } //reset value to dictionary lookup values[i++] = dic[oldIndex]; } } this._jointIndices.set(values, offset); } else if (this._jointIndices) { this.clearVertices(this._jointIndices); this._jointIndices = null; return; } this.invalidateVertices(this._jointIndices); this._verticesDirty[this._jointIndices.id] = false; }; TriangleElements.prototype.setJointWeights = function (values, offset) { if (offset === void 0) { offset = 0; } if (values == this._jointWeights) return; if (values instanceof AttributesView) { this.clearVertices(this._jointWeights); this._jointWeights = values; } else if (values) { if (!this._jointWeights) this._jointWeights = new AttributesView(Float32Array, this._jointsPerVertex, this._concatenatedBuffer); this._jointWeights.set(values, offset); } else if (this._jointWeights) { this.clearVertices(this._jointWeights); this._jointWeights = null; return; } this.invalidateVertices(this._jointWeights); this._verticesDirty[this._jointWeights.id] = false; }; /** * */ TriangleElements.prototype.dispose = function () { _super.prototype.dispose.call(this); if (this._positions) { this._positions.dispose(); this._positions = null; } if (this._normals) { this._normals.dispose(); this._normals = null; } if (this._tangents) { this._tangents.dispose(); this._tangents = null; } if (this._uvs) { this._uvs.dispose(); this._uvs = null; } if (this._jointIndices) { this._jointIndices.dispose(); this._jointIndices = null; } if (this._jointWeights) { this._jointWeights.dispose(); this._jointWeights = null; } if (this._faceNormals) { this._faceNormals.dispose(); this._faceNormals = null; } if (this._faceTangents) { this._faceTangents.dispose(); this._faceTangents = null; } }; TriangleElements.prototype.setIndices = function (values, offset) { if (offset === void 0) { offset = 0; } _super.prototype.setIndices.call(this, values, offset); this._faceNormalsDirty = true; this._faceTangentsDirty = true; if (this._autoDeriveNormals) this.invalidateVertices(this._normals); if (this._autoDeriveTangents) this.invalidateVertices(this._tangents); }; TriangleElements.prototype.copyTo = function (elements) { _super.prototype.copyTo.call(this, elements); //temp disable auto derives var autoDeriveNormals = this._autoDeriveNormals; var autoDeriveTangents = this._autoDeriveTangents; elements.autoDeriveNormals = this._autoDeriveNormals = false; elements.autoDeriveTangents = this._autoDeriveTangents = false; elements.setPositions(this.positions.clone()); if (this.normals) elements.setNormals(this.normals.clone()); if (this.tangents) elements.setTangents(this.tangents.clone()); if (this.uvs) elements.setUVs(this.uvs.clone()); elements.jointsPerVertex = this._jointsPerVertex; if (this.jointIndices) elements.setJointIndices(this.jointIndices.clone()); if (this.jointWeights) elements.setJointWeights(this.jointWeights.clone()); //return auto derives to cloned values elements.autoDeriveNormals = this._autoDeriveNormals = autoDeriveNormals; elements.autoDeriveTangents = this._autoDeriveTangents = autoDeriveTangents; if (this.scale9Indices) { elements.originalScale9Bounds = this.originalScale9Bounds; elements.scale9Grid = this.scale9Grid; elements.scale9Indices = this.scale9Indices; elements.initialScale9Positions = this.initialScale9Positions; } }; /** * Clones the current object * @return An exact duplicate of the current object. */ TriangleElements.prototype.clone = function () { var clone = new TriangleElements(this._concatenatedBuffer ? this._concatenatedBuffer.clone() : null); this.copyTo(clone); return clone; }; TriangleElements.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; } if (this.uvs) // only scale if uvs exist ElementsUtils.scale(scaleU, scaleV, 0, this.uvs, count || this._numVertices, offset); }; /** * Scales the geometry. * @param scale The amount by which to scale. */ TriangleElements.prototype.scale = function (scale, count, offset) { if (count === void 0) { count = 0; } if (offset === void 0) { offset = 0; } ElementsUtils.scale(scale, scale, scale, this.positions, count || this._numVertices, offset); }; TriangleElements.prototype.applyTransformation = function (transform, count, offset) { if (count === void 0) { count = 0; } if (offset === void 0) { offset = 0; } ElementsUtils.applyTransformation(transform, this.positions, this.normals, this.tangents, count || this._numVertices, offset); }; /** * Updates the tangents for each face. */ TriangleElements.prototype.updateFaceTangents = function () { this._faceTangents = ElementsUtils.generateFaceTangents(this.indices, this.positions, this.uvs || this.positions, this._faceTangents, this.numElements); this._faceTangentsDirty = false; }; /** * Updates the normals for each face. */ TriangleElements.prototype.updateFaceNormals = function () { this._faceNormals = ElementsUtils.generateFaceNormals(this.indices, this.positions, this._faceNormals, this.numElements); this._faceNormalsDirty = false; }; TriangleElements.prototype.testCollision = function (collision, box, closestFlag, material, count, offset) { if (offset === void 0) { offset = 0; } var rayPosition = collision.rayPosition; var rayDirection = collision.rayDirection; var t; var i0, i1, i2; var rx, ry, rz; var nx, ny, nz; var cx, cy, cz; var coeff, u, v, w; var p0x, p0y, p0z; var p1x, p1y, p1z; var p2x, p2y, p2z; var s0x, s0y, s0z; var s1x, s1y, s1z; var nl, nDotV, D, disToPlane; var Q1Q2, Q1Q1, Q2Q2, RQ1, RQ2; var collisionTriangleIndex = -1; var bothSides = material.bothSides; var positions = this.positions.get(count, offset); var posDim = this.positions.dimensions; var posStride = this.positions.stride; var indices; if (this.indices) { indices = this.indices.get(this.numElements); count = indices.length; } for (var index = 0; index < count; index += 3) { // sweep all triangles // evaluate triangle indices if (indices) { i0 = indices[index] * posStride; i1 = indices[index + 1] * posStride; i2 = indices[index + 2] * posStride; } else { i0 = index * posStride; i1 = (index + 1) * posStride; i2 = (index + 2) * posStride; } // evaluate triangle positions p0x = positions[i0]; p1x = positions[i1]; p2x = positions[i2]; s0x = p1x - p0x; // s0 = p1 - p0 s1x = p2x - p0x; // s1 = p2 - p0 p0y = positions[i0 + 1]; p1y = positions[i1 + 1]; p2y = positions[i2 + 1]; s0y = p1y - p0y; s1y = p2y - p0y; if (posDim == 3) { p0z = positions[i0 + 2]; p1z = positions[i1 + 2]; p2z = positions[i2 + 2]; s0z = p1z - p0z; s1z = p2z - p0z; // evaluate sides and triangle normal nx = s0y * s1z - s0z * s1y; // n = s0 x s1 ny = s0z * s1x - s0x * s1z; nz = s0x * s1y - s0y * s1x; nl = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz); // normalize n nx *= nl; ny *= nl; nz *= nl; } else { //2d hittest p0z = 0; p1z = 0; s0z = 0; s1z = 0; nx = 0; ny = 0; nz = ((s0x * s1y - s0y * s1x) > 0) ? 1 : -1; } // -- plane intersection test -- nDotV = nx * rayDirection.x + ny * +rayDirection.y + nz * rayDirection.z; // rayDirection . normal if ((!bothSides && nDotV < 0.0) || (bothSides && nDotV != 0.0)) { // an intersection must exist // find collision t D = -(nx * p0x + ny * p0y + nz * p0z); disToPlane = -(nx * rayPosition.x + ny * rayPosition.y + nz * rayPosition.z + D); t = disToPlane / nDotV; // find collision point cx = rayPosition.x + t * rayDirection.x; cy = rayPosition.y + t * rayDirection.y; cz = rayPosition.z + t * rayDirection.z; // collision point inside triangle? ( using barycentric coordinates ) Q1Q2 = s0x * s1x + s0y * s1y + s0z * s1z; Q1Q1 = s0x * s0x + s0y * s0y + s0z * s0z; Q2Q2 = s1x * s1x + s1y * s1y + s1z * s1z; rx = cx - p0x; ry = cy - p0y; rz = cz - p0z; RQ1 = rx * s0x + ry * s0y + rz * s0z; RQ2 = rx * s1x + ry * s1y + rz * s1z; coeff = (Q1Q1 * Q2Q2 - Q1Q2 * Q1Q2); if (Math.abs(coeff) < MIN_COEFF) // points are in a line (should be zero but rounding errors) continue; coeff = 1 / coeff; v = coeff * (Q2Q2 * RQ1 - Q1Q2 * RQ2); w = coeff * (-Q1Q2 * RQ1 + Q1Q1 * RQ2); if (v < 0) continue; if (w < 0) continue; u = 1 - v - w; if (!(u < 0) && t > 0 && t < collision.rayEntryDistance) { // all tests passed collisionTriangleIndex = index / 3; collision.rayEntryDistance = t; collision.position = collision.position || new Vector3D(); collision.position.setTo(cx, cy, cz); collision.normal = collision.normal || new Vector3D(); collision.normal.setTo(nx, ny, nz); if (this.uvs) { //uv calculations var uvs = this.uvs.get(this.numVertices); var uvStride = this.uvs.stride; var uIndex = indices ? indices[index] * uvStride : index * uvStride; var uv0 = new Vector3D(uvs[uIndex], uvs[uIndex + 1]); uIndex = indices ? indices[index + 1] * uvStride : (index + 1) * uvStride; var uv1 = new Vector3D(uvs[uIndex], uvs[uIndex + 1]); uIndex = indices ? indices[index + 2] * uvStride : (index + 2) * uvStride; var uv2 = new Vector3D(uvs[uIndex], uvs[uIndex + 1]); collision.uv = new Point(u * uv0.x + v * uv1.x + w * uv2.x, u * uv0.y + v * uv1.y + w * uv2.y); } collision.elementIndex = collisionTriangleIndex; // if not looking for best hit, first found will do... if (!closestFlag) return true; } } } if (collisionTriangleIndex >= 0) return true; return false; }; TriangleElements.isIE = !!navigator.userAgent.match(/Trident/g) || !!navigator.userAgent.match(/MSIE/g); TriangleElements.assetType = '[asset TriangleElements]'; return TriangleElements; }(ElementsBase)); export { TriangleElements }; import { Stage, ContextGLDrawMode, ContextGLProgramType } from '@awayjs/stage'; import { RenderGroup } from '../RenderGroup'; import { _Stage_ElementsBase } from '../base/_Stage_ElementsBase'; import { Settings } from '../Settings'; import { _Render_ElementsBase } from '../base/_Render_ElementsBase'; /** * * @class away.pool._Stage_TriangleElements */ var _Stage_TriangleElements = /** @class */ (function (_super) { __extends(_Stage_TriangleElements, _super); function _Stage_TriangleElements() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._vaoIsInvalid = true; return _this; } _Stage_TriangleElements.prototype.init = function (triangleElements, stage) { _super.prototype.init.call(this, triangleElements, stage); this._triangleElements = triangleElements; if (!this._triangleElements.isDynamic && Settings.ALLOW_VAO && stage.context.hasVao) { this._vao = stage.context.createVao(); } }; _Stage_TriangleElements.prototype._onInvalidateIndices = function (event) { _super.prototype._onInvalidateIndices.call(this, event); this._vaoIsInvalid = true; // drop vao every invalidation because buffers can be rebound // if (this._vao) { // this._vao.dispose(); // this._vao = null; // } }; _Stage_TriangleElements.prototype._onInvalidateVertices = function (event) { _super.prototype._onInvalidateVertices.call(this, event); this._vaoIsInvalid = true; // drop vao every invalidation because buffers can be rebound // if (this._vao) { // this._vao.dispose(); // this._vao = null; // } }; _Stage_TriangleElements.prototype.onInvalidate = function (event) { _super.prototype.onInvalidate.call(this, event); this._vaoIsInvalid = true; // drop vao every invalidation because buffers can be rebound // if (this._vao) { // this._vao.dispose(); // this._vao = null; // } }; _Stage_TriangleElements.prototype.onClear = function (event) { _super.prototype.onClear.call(this, event); this._triangleElements = null; this._vaoIsInvalid = true; if (this._vao) { this._vao.dispose(); this._vao = null; } }; _Stage_TriangleElements.prototype._setRenderState = function (renderRenderable, shader) { this._vao && this._vao.bind(); _super.prototype._setRenderState.call(this, renderRenderable, shader); if (!this._vao || this._vaoIsInvalid) { //set buffers //TODO: find a better way to update a concatenated buffer when autoderiving if (shader.normalIndex >= 0 && this._triangleElements.autoDeriveNormals) this._triangleElements.normals; if (shader.tangentIndex >= 0 && this._triangleElements.autoDeriveTangents) this._triangleElements.tangents; if (shader.curvesIndex >= 0) this.activateVertexBufferVO(shader.curvesIndex, this._triangleElements.getCustomAtributes('curves')); if (shader.uvIndex >= 0) this.activateVertexBufferVO(shader.uvIndex, this._triangleElements.uvs || this._triangleElements.positions); if (shader.secondaryUVIndex >= 0) { this.activateVertexBufferVO(shader.secondaryUVIndex, this._triangleElements.getCustomAtributes('secondaryUVs') || this._triangleElements.uvs || this._triangleElements.positions); } if (shader.normalIndex >= 0) this.activateVertexBufferVO(shader.normalIndex, this._triangleElements.normals); if (shader.tangentIndex >= 0) this.activateVertexBufferVO(shader.tangentIndex, this._triangleElements.tangents); if (shader.jointIndexIndex >= 0) this.activateVertexBufferVO(shader.jointIndexIndex, this._triangleElements.jointIndices); if (shader.jointWeightIndex >= 0) this.activateVertexBufferVO(shader.jointIndexIndex, this._triangleElements.jointWeights); this.activateVertexBufferVO(0, this._triangleElements.positions); this._vaoIsInvalid = false; } }; _Stage_TriangleElements.prototype.draw = function (renderRenderable, shader, count, offset) { var modern = shader.supportModernAPI; //set constants if (shader.sceneMatrixIndex >= 0) { shader.sceneMatrix.copyFrom(renderRenderable.renderSceneTransform, true); shader.viewMatrix.copyFrom(shader.view.viewMatrix3D, true); } else { var matrix3D = Matrix3D.CALCULATION_MATRIX; matrix3D.copyFrom(renderRenderable.renderSceneTransform); matrix3D.append(shader.view.viewMatrix3D); shader.viewMatrix.copyFrom(matrix3D, true); } if (!modern) { var context = this._stage.context; context.setProgramConstantsFromArray(ContextGLProgramType.VERTEX, shader.vertexConstantData); context.setProgramConstantsFromArray(ContextGLProgramType.FRAGMENT, shader.fragmentConstantData); } else { shader.syncUniforms(); } if (this._indices) { this.getIndexBufferGL().draw(ContextGLDrawMode.TRIANGLES, offset * 3, count * 3 || this.numIndices); } else { this._stage.context.drawVertices(ContextGLDrawMode.TRIANGLES, offset, count || this.numVertices); } this._vao && this._vao.unbind(); }; /** * //TODO * * @param pool * @param renderable * @param level * @param indexOffset * @returns {away.pool.GL_ShapeRenderable} * @protected */ _Stage_TriangleElements.prototype._pGetOverflowElements = function () { return this._triangleElements.getNewAbstraction(this._stage); }; return _Stage_TriangleElements; }(_Stage_ElementsBase)); export { _Stage_TriangleElements }; /** * @class away.pool.LineMaterialPool */ var _Render_TriangleElements = /** @class */ (function (_super) { __extends(_Render_TriangleElements, _super); function _Render_TriangleElements() { return _super !== null && _super.apply(this, arguments) || this; } _Render_TriangleElements.prototype._includeDependencies = function (shader) { }; _Render_TriangleElements.prototype._getVertexCode = function (shader, registerCache, sharedRegisters) { var code = ''; //get the projection coordinates var position = ((shader.globalPosDependencies > 0) ? sharedRegisters.globalPositionVertex : sharedRegisters.animatedPosition); //reserving vertex constants for projection matrix var viewMatrixReg = registerCache.getFreeVertexConstant(); registerCache.getFreeVertexConstant(); registerCache.getFreeVertexConstant(); registerCache.getFreeVertexConstant(); shader.viewMatrixIndex = viewMatrixReg.index * 4; if (shader.projectionDependencies > 0) { sharedRegisters.projectionFragment = registerCache.getFreeVarying(); var temp = registerCache.getFreeVertexVectorTemp(); code += 'm44 ' + temp + ', ' + position + ', ' + viewMatrixReg + '\n' + 'mov ' + sharedRegisters.projectionFragment + ', ' + temp + '\n' + 'mov op, ' + temp + '\n'; } else { code += 'm44 op, ' + position + ', ' + viewMatrixReg + '\n'; } return code; }; _Render_TriangleElements.prototype._getFragmentCode = function (shader, registerCache, sharedRegisters) { return ''; }; return _Render_TriangleElements; }(_Render_ElementsBase)); export { _Render_TriangleElements }; RenderGroup.registerElements(_Render_TriangleElements, TriangleElements); Stage.registerAbstraction(_Stage_TriangleElements, TriangleElements);