UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

59 lines (56 loc) 1.73 kB
import { Vec3 } from '../../../core/math/vec3.js'; import { CULLFACE_NONE } from '../../../platform/graphics/constants.js'; import { PlaneGeometry } from '../../../scene/geometry/plane-geometry.js'; import { TriData } from '../tri-data.js'; import { Shape } from './shape.js'; var UPDATE_EPSILON = 1e-6; class PlaneShape extends Shape { set size(value) { this._size = value != null ? value : 1; this._updateTransform(); } get size() { return this._size; } set gap(value) { this._gap = value != null ? value : 0; this._updateTransform(); } get gap() { return this._gap; } set flipped(value) { if (this._flipped.distance(value) < UPDATE_EPSILON) { return; } this._flipped.copy(value); this.entity.setLocalPosition(this._getPosition()); } get flipped() { return this._flipped; } _getPosition() { var offset = this._size / 2 + this._gap; var position = new Vec3(this._flipped.x ? -offset : offset, this._flipped.y ? -offset : offset, this._flipped.z ? -offset : offset); position[this.axis] = 0; return position; } _createPlane() { this._createRoot('plane'); this._updateTransform(); this._addRenderMesh(this.entity, 'plane', this._shading); } _updateTransform() { this.entity.setLocalPosition(this._getPosition()); this.entity.setLocalEulerAngles(this._rotation); this.entity.setLocalScale(this._size, this._size, this._size); } constructor(device, options = {}){ super(device, options), this._cull = CULLFACE_NONE, this._size = 0.2, this._gap = 0.1, this._flipped = new Vec3(); this.triData = [ new TriData(new PlaneGeometry()) ]; this._createPlane(); } } export { PlaneShape };