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AAC,WAAW,cAAc,QAAQ,UAAU;AAAA;AAAA;AAGhG,gBAAU,SAAS,cAAc,KAAK;AAAA;AAGxC,QAAI,qBAAqB,+DAAY,EAAE;AACrC,YAAM,QAAQ,UAAU,SAAS;AACjC,YAAM,UAAU,KAAK,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM;AAEjD,YAAM,SAAS,UAAU,eAAgB;AAEzC,UAAI,KAAK,oBAAoB,uDAA0B,EAAE;AACvD,YAAI,KAAK,SAAS,WAAW,WAAW,QAAQ;AAC9C,cAAI,WAAW,KAAK;AAEpB,cAAI,WAAW;AAAI,uBAAW;AAE9B,cAAI,WAAW;AAAI,uBAAW;AAE9B,eAAK,SAAS;AACd,eAAK,WAAW,IAAI,uDAA0B,CAAC,QAAQ,UAAU;AAAA;AAAA;AAAA;AAKvE,cAAU,SAAS,iBAAiB,KAAK;AACzC,cAAU,SAAS,mBAAmB,KAAK;AAAA;AAAA,EAI7C,kBAAkB;AAChB,SAAK,uBAAuB;AAC5B,SAAK,yBAAyB;AAC9B,SAAK,aAAa;AAClB,SAAK;AAAA;AAAA;AA/NT;AACS,wCAAoB;AAkO7B,2DAAoB,CAAC","sources":["webpack://roguetemplateproject/webpack/universalModuleDefinition","webpack://roguetemplateproject/./Assets/rogue_packages/BeardScript/rogue-cannon/Components/_Editor/CannonBodyWireframe.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"rogue-editor-user-scripts\"] = factory();\n\telse\n\t\troot[\"rogue-editor-user-scripts\"] = factory();\n})(self, () => {\nreturn ","import * as RE from 'rogue-engine';\r\nimport * as THREE from 'three';\r\n\r\nimport CannonBox from '../Shapes/CannonBox.re';\r\nimport CannonSphere from '../Shapes/CannonSphere.re';\r\nimport CannonShape from '../Shapes/CannonShape';\r\nimport CannonCylinder from '../Shapes/CannonCylinder.re';\r\nimport CannonTrimesh from '../Shapes/CannonTrimesh.re';\r\n\r\nexport default class CannonBodyWireframe extends RE.Component {\r\n static isEditorComponent = true;\r\n\r\n selectedObjects: THREE.Object3D[] = [];\r\n colliders: THREE.Object3D[] = [];\r\n wireframeMaterial = new THREE.MeshStandardMaterial({wireframe: true, emissive: new THREE.Color(\"#00FF00\"), color: new THREE.Color(\"#000000\")});\r\n\r\n private handleOnComponentAdded = {stop: () => {}};\r\n private handleOnComponentRemoved = {stop: () => {}};\r\n\r\n private handleOnPlay = {stop: () => {}};\r\n\r\n private resetHandler = (component: RE.Component) => {\r\n component instanceof CannonShape && this.setupImpostors();\r\n }\r\n\r\n start() {\r\n this.handleOnComponentAdded.stop();\r\n this.handleOnComponentRemoved.stop();\r\n this.handleOnPlay.stop();\r\n\r\n this.handleOnComponentAdded = RE.onComponentAdded(this.resetHandler);\r\n this.handleOnComponentRemoved = RE.onComponentRemoved(this.resetHandler);\r\n\r\n this.handleOnPlay = RE.Runtime.onPlay(() => {\r\n this.handleOnComponentAdded.stop();\r\n this.handleOnComponentRemoved.stop();\r\n this.cleanupImpostors();\r\n });\r\n }\r\n\r\n afterUpdate() {\r\n const selectedObjects = window[\"rogue-editor\"].Project.selectedObjects as THREE.Object3D[];\r\n\r\n if (!this.arraysAreEqual(selectedObjects, this.selectedObjects)) {\r\n this.selectedObjects = selectedObjects.slice(0);\r\n this.setupImpostors();\r\n }\r\n\r\n if (this.selectedObjects.length === 0) return;\r\n\r\n this.updateImpostors();\r\n }\r\n\r\n private updateImpostors() {\r\n this.colliders.forEach(impostor => {\r\n this.updateColliderMesh(impostor.userData.cannonShape, impostor as THREE.Mesh);\r\n });\r\n }\r\n\r\n private cleanupImpostors() {\r\n this.colliders.forEach(impostor => {\r\n impostor.userData.cannonShape = null;\r\n RE.App.currentScene.remove(impostor);\r\n RE.dispose(impostor);\r\n });\r\n\r\n this.colliders = [];\r\n }\r\n\r\n private setupImpostors() {\r\n this.cleanupImpostors();\r\n\r\n this.selectedObjects.forEach(selected => {\r\n selected.traverse(object => {\r\n const objComponents = RE.components[object.uuid];\r\n\r\n if (!objComponents) return;\r\n\r\n objComponents.forEach(component => {\r\n if (!(component instanceof CannonShape)) return;\r\n\r\n let impostor = RE.App.currentScene.getObjectByName(\"EDITOR_OBJECT_BB_\" + object.uuid);\r\n\r\n if (impostor) return;\r\n\r\n impostor = this.getColliderMesh(component);\r\n\r\n if (impostor) {\r\n impostor.name = \"EDITOR_OBJECT_BB_\" + object.uuid;\r\n impostor.userData.isEditorObject = true;\r\n RE.App.currentScene.add(impostor);\r\n } else {\r\n return;\r\n }\r\n\r\n impostor.userData.cannonShape = component;\r\n this.colliders.push(impostor);\r\n });\r\n });\r\n });\r\n }\r\n\r\n private arraysAreEqual(array1: any[], array2: any[]) {\r\n if (array1.length !== array2.length) return false;\r\n\r\n return array1.every((element, i) => {\r\n return array2[i] === element;\r\n });\r\n }\r\n\r\n private getColliderMesh(component: CannonShape): THREE.Mesh | undefined {\r\n if (component instanceof CannonBox) {\r\n return new THREE.Mesh(\r\n new THREE.BoxBufferGeometry(),\r\n this.wireframeMaterial,\r\n );\r\n }\r\n\r\n if (component instanceof CannonCylinder) {\r\n const radiusTop = component.radiusTopOffset;\r\n const radiusBottom = component.radiusBottomOffset;\r\n const height = component.heightOffset;\r\n const mesh = new THREE.Mesh(\r\n new THREE.CylinderBufferGeometry(radiusTop, radiusBottom, height, component.segments),\r\n this.wireframeMaterial,\r\n );\r\n\r\n return mesh;\r\n }\r\n\r\n if (component instanceof CannonSphere) {\r\n const scale = component.object3d.scale;\r\n const maxSide = Math.max(scale.x, scale.y, scale.z);\r\n\r\n const radius = component.radiusOffset * (maxSide);\r\n const compensatedRadius = radius + (radius * 0.01);\r\n const segments = 15;\r\n\r\n return new THREE.Mesh(\r\n new THREE.SphereBufferGeometry(compensatedRadius, segments, segments),\r\n this.wireframeMaterial,\r\n );\r\n }\r\n\r\n if (component instanceof CannonTrimesh) {\r\n\r\n if (!component.shape) component.createShape();\r\n\r\n if (component.shape) {\r\n const geometry = new THREE.BufferGeometry();\r\n const mesh = new THREE.Mesh(geometry, this.wireframeMaterial);\r\n\r\n const points: THREE.Vector3[] = [];\r\n\r\n for (let i = 0; i < component.shape.vertices.length; i+=3) {\r\n const point = new THREE.Vector3(\r\n component.shape.vertices[i],\r\n component.shape.vertices[i + 1],\r\n component.shape.vertices[i + 2]\r\n );\r\n\r\n points.push(point);\r\n }\r\n\r\n geometry.setFromPoints(points);\r\n\r\n return mesh;\r\n }\r\n }\r\n\r\n return;\r\n }\r\n\r\n private updateColliderMesh(component: CannonShape, mesh: THREE.Mesh) {\r\n if (component instanceof CannonBox) {\r\n component.object3d.getWorldScale(mesh.scale);\r\n\r\n mesh.scale.set(\r\n component.sizeOffset.x * (mesh.scale.x),\r\n component.sizeOffset.y * (mesh.scale.y),\r\n component.sizeOffset.z * (mesh.scale.z)\r\n );\r\n }\r\n\r\n if (component instanceof CannonCylinder) {\r\n const radiusTop = component.radiusTopOffset;\r\n const radiusBottom = component.radiusBottomOffset;\r\n const height = component.heightOffset;\r\n\r\n if (mesh.geometry instanceof THREE.CylinderBufferGeometry) {\r\n if (\r\n mesh.geometry.parameters.radiusTop !== radiusTop ||\r\n mesh.geometry.parameters.radiusBottom !== radiusBottom ||\r\n mesh.geometry.parameters.height !== height ||\r\n mesh.geometry.parameters.radialSegments !== component.segments\r\n ) {\r\n mesh.geometry.dispose();\r\n mesh.geometry = new THREE.CylinderBufferGeometry(radiusTop, radiusBottom, height, component.segments);\r\n }\r\n }\r\n component.object3d.getWorldScale(mesh.scale);\r\n }\r\n\r\n if (component instanceof CannonSphere) {\r\n const scale = component.object3d.scale;\r\n const maxSide = Math.max(scale.x, scale.y, scale.z);\r\n\r\n const radius = component.radiusOffset * (maxSide);\r\n\r\n if (mesh.geometry instanceof THREE.SphereBufferGeometry) {\r\n if (mesh.geometry.parameters.radius !== radius) {\r\n let segments = 10 * radius;\r\n\r\n if (segments < 15) segments = 15;\r\n\r\n if (segments > 50) segments = 50;\r\n\r\n mesh.geometry.dispose();\r\n mesh.geometry = new THREE.SphereBufferGeometry(radius, segments, segments);\r\n }\r\n }\r\n }\r\n\r\n component.object3d.getWorldPosition(mesh.position);\r\n component.object3d.getWorldQuaternion(mesh.quaternion);\r\n // component.object3d.getWorldScale(mesh.scale);\r\n }\r\n\r\n onBeforeRemoved() {\r\n this.handleOnComponentAdded.stop();\r\n this.handleOnComponentRemoved.stop();\r\n this.handleOnPlay.stop();\r\n this.cleanupImpostors();\r\n }\r\n}\r\n\r\nRE.registerComponent(CannonBodyWireframe);\r\n"],"names":[],"sourceRoot":""}