UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.72 kB
import{Quat as e}from"../../../core/math/quat.js";import{Vec3 as t}from"../../../core/math/vec3.js";import{Entity as i}from"../../../framework/entity.js";import{ConeGeometry as s}from"../../../scene/geometry/cone-geometry.js";import{CylinderGeometry as h}from"../../../scene/geometry/cylinder-geometry.js";import{TriData as n}from"../tri-data.js";import{Shape as r}from"./shape.js";const a=new t,_=new t,o=new e;class l extends r{constructor(e,t={}){super(e,t),this._gap=0,this._lineThickness=.02,this._lineLength=.5,this._arrowThickness=.12,this._arrowLength=.18,this._tolerance=.1,this._head=void 0,this._line=void 0,this._flipped=!1,this.triData=[new n(new s),new n(new h,1)],this._createArrow()}set gap(e){this._gap=null!=e?e:0,this._updateHead(),this._updateLine()}get gap(){return this._gap}set lineThickness(e){this._lineThickness=null!=e?e:1,this._updateHead(),this._updateLine()}get lineThickness(){return this._lineThickness}set lineLength(e){this._lineLength=null!=e?e:1,this._updateHead(),this._updateLine()}get lineLength(){return this._lineLength}set arrowThickness(e){this._arrowThickness=null!=e?e:1,this._updateHead()}get arrowThickness(){return this._arrowThickness}set arrowLength(e){this._arrowLength=null!=e?e:1,this._updateHead()}get arrowLength(){return this._arrowLength}set tolerance(e){this._tolerance=e,this._updateLine()}get tolerance(){return this._tolerance}set flipped(e){this._flipped!==e&&(this._flipped=e,this._rotation.equals(t.ZERO)?a.set(0,0,this._flipped?180:0):a.copy(this._rotation).mulScalar(this._flipped?-1:1),this._line.enabled=!this._flipped,this.entity.setLocalEulerAngles(a))}get flipped(){return this._flipped}_createArrow(){this._createRoot("arrow"),this._head=new i(`head:${this.axis}`),this.entity.addChild(this._head),this._updateHead(),this._addRenderMesh(this._head,"cone",this._shading),this._line=new i(`line:${this.axis}`),this.entity.addChild(this._line),this._updateLine(),this._addRenderMesh(this._line,"cylinder",this._shading)}_updateHead(){a.set(0,this._gap+.5*this._arrowLength+this._lineLength,0),o.set(0,0,0,1),_.set(this._arrowThickness,this._arrowLength,this._arrowThickness),this.triData[0].setTransform(a,o,_),this._head.setLocalPosition(0,this._gap+.5*this._arrowLength+this._lineLength,0),this._head.setLocalScale(this._arrowThickness,this._arrowLength,this._arrowThickness)}_updateLine(){a.set(0,this._gap+.5*this._lineLength,0),o.set(0,0,0,1),_.set(this._lineThickness+this._tolerance,this._lineLength,this._lineThickness+this._tolerance),this.triData[1].setTransform(a,o,_),this._line.setLocalPosition(0,this._gap+.5*this._lineLength,0),this._line.setLocalScale(this._lineThickness,this._lineLength,this._lineThickness)}}export{l as ArrowShape};