import Gizmo from './Gizmo' ; import TransformComponent from '../components/TransformComponent' ; import SceneGraphComponent from '../components/SceneGraphComponent' ; import MeshComponent from '../components/MeshComponent' ; import MeshRendererComponent from '../components/MeshRendererComponent' ; import { PrimitiveMode } from '../definitions/PrimitiveMode' ; import { VertexAttribute } from '../definitions/VertexAttribute' ; import { CompositionType } from '../definitions/CompositionType' ; import { Primitive } from '../geometry/Primitive' ; import Vector3 from '../math/Vector3' ; import Mesh from '../geometry/Mesh' ; import Entity from '../core/Entity' ; /**
 * AABB Gizmo class
 */ export default class AABBGizmo extends Gizmo { private static __mesh ? : Mesh ; param target constructor ( target ) { super ( target ) ; } get isSetup ( ) { if ( this . __topEntity != null ) { return true ; } else { return false ; } } private _setup ( ) { if ( this . __toSkipSetup ( ) ) { return ; } this . __topEntity = this . __entityRepository . createEntity ( [ TransformComponent , SceneGraphComponent , MeshComponent , MeshRendererComponent , ] ) ; this . __topEntity . tryToSetUniqueName ( `AABBGizmo_of_${ this . __target . uniqueName }` , true ) ; this . __topEntity . getSceneGraph ( ) . toMakeWorldMatrixTheSameAsLocalMatrix = true ; this . __target . getSceneGraph ( ) . _addGizmoChild ( this . __topEntity . getSceneGraph ( ) ) ; const meshComponent = this . __topEntity . getMesh ( ) ; AABBGizmo . __mesh = new Mesh ( ) ; AABBGizmo . __mesh . addPrimitive ( AABBGizmo . generatePrimitive ( ) ) ; meshComponent . setMesh ( AABBGizmo . __mesh ) ; this . setGizmoTag ( ) ; } returns private static generatePrimitive ( ) { const indices = new Uint32Array ( [ 0 , 1 , 1 , 2 , 2 , 3 , 3 , 0 , 4 , 5 , 5 , 6 , 6 , 7 , 7 , 4 , 0 , 3 , 3 , 7 , 7 , 4 , 4 , 0 , 1 , 2 , 2 , 6 , 6 , 5 , 5 , 1 , 0 , 1 , 1 , 5 , 5 , 4 , 4 , 0 , 3 , 2 , 2 , 6 , 6 , 7 , 7 , 3 , ] ) ; const length = 1 ; const positions = new Float32Array ( [ - length , - length , - length , length , - length , - length , length , length , - length , - length , length , - length , - length , - length , length , length , - length , length , length , length , length , - length , length , length , ] ) ; const primitive = Primitive . createPrimitive ( { indices : indices , attributeCompositionTypes : [ CompositionType . Vec3 ] , attributeSemantics : [ VertexAttribute . Position ] , attributes : [ positions ] , primitiveMode : PrimitiveMode . Lines , } ) ; return primitive ; } private _update ( ) { if ( this . __topEntity == null ) { return ; } const sg = this . __target . getSceneGraph ( ) ; const aabb = sg . worldAABB ; this . __topEntity . getTransform ( ) . translate = aabb . centerPoint ; this . __topEntity . getTransform ( ) . scale = Vector3 . fromCopyArray ( [ aabb . sizeX / 2 , aabb . sizeY / 2 , aabb . sizeZ / 2 , ] ) ; } }