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EAAE;AACvC,kBAAM,gBAAgB,UAAU,iBAAiB,UAAU;AAE3D,gBAAI,eAAe;AACjB,4BAAc;AAAA;AAGhB,sBAAU;AAGV,iBAAK,UAAU,KAAK;AAAA;AAAA;AAAA;AAAA;AAM5B,kEAAuB,CAAC,KAAK;AAAA;AAAA,EAGvB,eAAe,QAAe,QAAe;AACnD,QAAI,OAAO,WAAW,OAAO;AAAQ,aAAO;AAE5C,WAAO,OAAO,MAAM,CAAC,SAAS,MAAM;AAClC,aAAO,OAAO,OAAO;AAAA;AAAA;AAAA,EAIzB,kBAAkB;AAChB,qEAA0B,CAAC,KAAK;AAChC,SAAK,uBAAuB;AAC5B,SAAK,yBAAyB;AAC9B,SAAK,aAAa;AAClB,SAAK;AAAA;AAAA;AAzLT;AACS,wCAAoB;AA4L7B,2DAAoB,CAAC","sources":["webpack://roguetemplateproject/webpack/universalModuleDefinition","webpack://roguetemplateproject/./Assets/rogue_packages/BeardScript/rogue-cannon/Components/_Editor/CannonBodyWireframe.ts","webpack://roguetemplateproject/./Assets/rogue_packages/RogueEngine/rogue-rapier/Components/_Editor/RapierBodyWireframe.re.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","import * as RE from 'rogue-engine';\r\nimport * as THREE from 'three';\r\n\r\nimport RapierCollider from '../Colliders/RapierCollider';\r\nimport RAPIER from '@dimforge/rapier3d-compat';\r\nimport RapierBody from '../RapierBody.re';\r\nimport RogueRapier from '@RE/RogueEngine/rogue-rapier/Lib/RogueRapier';\r\n\r\nexport default class RapierBodyWireframe extends RE.Component {\r\n static isEditorComponent = true;\r\n\r\n selectedObjects: THREE.Object3D[] = [];\r\n colliders: (RapierCollider | RapierBody)[] = [];\r\n\r\n lines = new THREE.LineSegments(\r\n new THREE.BufferGeometry(),\r\n new THREE.LineBasicMaterial({ color: new THREE.Color(\"#00FF00\") })\r\n );\r\n\r\n world: RAPIER.World;\r\n initializedPhysics = false;\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 RapierCollider && this.setupImpostors();\r\n }\r\n\r\n async initPhysics() {\r\n await RAPIER.init();\r\n }\r\n\r\n start() {\r\n this.initializedPhysics = false;\r\n\r\n this.lines.geometry.computeBoundingSphere();\r\n this.lines.frustumCulled = false;\r\n\r\n this.initPhysics().then(() => {\r\n this.world = new RAPIER.World({x: 0, y: 0, z: 0});\r\n RogueRapier.world = this.world;\r\n this.initializedPhysics = true;\r\n });\r\n\r\n RE.App.currentScene.remove(this.lines);\r\n\r\n this.lines.userData.isEditorObject = true;\r\n RE.App.currentScene.add(this.lines);\r\n\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 });\r\n }\r\n\r\n resetComponents() {\r\n this.selectedObjects.forEach(selected => {\r\n if (!selected) return;\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 RapierBody || component instanceof RapierCollider) {\r\n component.initialized = false;\r\n }\r\n });\r\n });\r\n });\r\n }\r\n\r\n afterUpdate() {\r\n this.lines.visible = false;\r\n if (!this.initializedPhysics) return;\r\n\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.resetComponents();\r\n this.setupImpostors();\r\n }\r\n\r\n if (!this.world || (this.world && this.world.bodies.len() === 0)) {\r\n return;\r\n }\r\n\r\n this.updateImpostors();\r\n }\r\n\r\n private updateImpostors() {\r\n this.lines.visible = true;\r\n this.world.step();\r\n\r\n const flagForRemoval: (RapierCollider | RapierBody)[] = [];\r\n\r\n this.colliders.forEach(component => {\r\n if (component instanceof RapierCollider && component.object3d && component.bodyComponent) {\r\n if (!component.enabled) {\r\n component.initialized = false;\r\n flagForRemoval.push(component);\r\n return;\r\n }\r\n const pos = component.bodyComponent.object3d.position;\r\n const rot = component.bodyComponent.object3d.quaternion;\r\n component.body.setTranslation(new RAPIER.Vector3(pos.x, pos.y, pos.z), false);\r\n component.body.setRotation(new RAPIER.Quaternion(rot.x, rot.y, rot.z, rot.w), false);\r\n component.setColliderRot();\r\n component.setColliderPos();\r\n }\r\n });\r\n\r\n flagForRemoval.forEach(component => this.colliders.splice(this.colliders.indexOf(component), 1))\r\n\r\n let buffers = this.world.debugRender();\r\n\r\n this.lines.geometry.setAttribute(\r\n \"position\",\r\n new THREE.BufferAttribute(buffers.vertices, 3),\r\n );\r\n\r\n this.lines.geometry.setAttribute(\r\n \"color\",\r\n new THREE.BufferAttribute(buffers.colors, 4),\r\n );\r\n }\r\n\r\n private async cleanupImpostors() {\r\n RogueRapier.world && RogueRapier.world.bodies.forEach(body => RogueRapier.world.removeRigidBody(body));\r\n this.lines.visible = false;\r\n RE.App.currentScene.remove(this.lines);\r\n\r\n this.colliders = [];\r\n }\r\n\r\n private async setupImpostors() {\r\n await 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 RapierBody) {\r\n component.init();\r\n this.colliders.push(component);\r\n }\r\n\r\n if (component instanceof RapierCollider) {\r\n const bodyComponent = component.getBodyComponent(component.object3d);\r\n\r\n if (bodyComponent) {\r\n bodyComponent.init();\r\n }\r\n\r\n component.init();\r\n // component.collider && \r\n // component.collider.setSensor(true);\r\n this.colliders.push(component);\r\n }\r\n });\r\n });\r\n });\r\n\r\n RE.App.currentScene.add(this.lines);\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 onBeforeRemoved() {\r\n RE.App.currentScene.remove(this.lines);\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(RapierBodyWireframe);\r\n"],"names":[],"sourceRoot":""}