8000 Ir 8616 revive bounding box by danskate · Pull Request #2018 · ir-engine/ir-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ir 8616 revive bounding box #2018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function SelectionBox({
) {
setComponent(simulationEntity, BoundingBoxComponent)
updateBoundingBox(simulationEntity)
const boundingBox = getComponent(simulationEntity, BoundingBoxComponent).box
const boundingBox = getComponent(simulationEntity, BoundingBoxComponent).worldBox
const status = frustum.intersectsBox(boundingBox)
if (status) {
const uuid = UUIDComponent.get(entity)
Expand Down
3 changes: 1 addition & 2 deletions packages/editor/src/systems/ActiveHelperSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import { ColliderComponent } from '@ir-engine/spatial/src/physics/components/Col
import { ObjectComponent } from '@ir-engine/spatial/src/renderer/components/ObjectComponent'
import { setVisibleComponent, VisibleComponent } from '@ir-engine/spatial/src/renderer/components/VisibleComponent'
import { ObjectLayerMasks, ObjectLayers } from '@ir-engine/spatial/src/renderer/constants/ObjectLayers'
import { BoundingBoxComponent } from '@ir-engine/spatial/src/transform/components/BoundingBoxComponent'
import { Raycaster, Vector3 } from 'three'
import { TransformGizmoControlComponent } from '../classes/gizmo/transform/TransformGizmoControlComponent'
import { iconGizmoArrow, iconGizmoYHelper, setupGizmo } from '../constants/GizmoPresets'
Expand Down Expand Up @@ -136,7 +135,7 @@ const ActiveHelperReactor = () => {
}

if (getComponent(entity, ActiveHelperComponent).volumeEnabled) {
setComponent(entity, BoundingBoxComponent)
setComponent(entity, ActiveHelperComponent, { volumeControlled: true })
}
return iconGizmo
},
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/gltf/GLTFComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { ObjectLayerMaskComponent } from '@ir-engine/spatial/src/renderer/compon
import { SceneComponent } from '@ir-engine/spatial/src/renderer/components/SceneComponents'
import { ObjectLayers } from '@ir-engine/spatial/src/renderer/constants/ObjectLayers'
import { ResourceType } from '@ir-engine/spatial/src/resources/ResourceState'
import { BoundingBoxComponent } from '@ir-engine/spatial/src/transform/components/BoundingBoxComponent'
import { LoaderUtils } from 'three'
import { loadResource } from '../assets/functions/resourceLoaderFunctions'
import { FileLoader } from '../assets/loaders/base/FileLoader'
Expand Down Expand Up @@ -277,6 +278,7 @@ export const GLTFComponentReactor = () => {
useEffect(() => {
if (!sceneLoaded) return
setComponent(entity, ActiveHelperComponent, { volumeEnabled: true })
setComponent(entity, BoundingBoxComponent)
}, [sceneLoaded])

const dependencies = gltfComponent.dependencies.get(NO_PROXY_STEALTH) as ComponentDependencies | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('ClientInputHeuristics', () => {
const box = new Box3(boxMin, boxMax)

setComponent(testEntity, BoundingBoxComponent)
getMutableComponent(testEntity, BoundingBoxComponent).box.set(box)
getMutableComponent(testEntity, BoundingBoxComponent).worldBox.set(box)

const inputState = getMutableState(InputState)
inputState.inputBoundingBoxes.set(new Set([testEntity]))
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('ClientInputHeuristics', () => {

for (const box of boxes) {
setComponent(box.entity, BoundingBoxComponent)
getMutableComponent(box.entity, BoundingBoxComponent).box.set(box.box)
getMutableComponent(box.entity, BoundingBoxComponent).worldBox.set(box.box)
}

const inputState = getMutableState(InputState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export function boundingBoxHeuristic(
if (!filterEntitiesByViewer(entity, viewerEntity)) continue
const boundingBox = getOptionalComponent(entity, BoundingBoxComponent)
if (!boundingBox) continue
const hit = ray.intersectBox(boundingBox.box, hitTarget)
const hit = ray.intersectBox(boundingBox.worldBox, hitTarget)
if (hit) {
intersectionData.add({ entity, distance: ray.origin.distanceTo(hitTarget) })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Infinite Reality Engine. All Rights Reserved.
*/

import { useEffect } from 'react'
import { Box3, Box3Helper, BufferGeometry, Mesh } from 'three'
import { Box3, Box3Helper, BufferGeometry, Matrix4, Mesh } from 'three'

import { EntityTreeComponent, createEntity, iterateEntityNode, removeEntity, useEntityContext } from '@ir-engine/ecs'
import {
Expand Down Expand Up @@ -56,6 +56,7 @@ export const BoundingBoxComponent = defineComponent({

schema: S.Object({
box: T.Box3(),
worldBox: T.Box3(),
helper: S.Entity()
}),

Expand Down Expand Up @@ -119,12 +120,24 @@ export const updateBoundingBox = (entity: Entity) => {
return
}

TransformComponent.computeTransformMatrixWithChildren(entity)

const box = boxComponent.box
const worldBox = boxComponent.worldBox
box.makeEmpty()
worldBox.makeEmpty()

const entityTransform = getOptionalComponent(entity, TransformComponent)
const entityMatrixI AE96 nverse = entityTransform
? new Matrix4().copy(entityTransform.matrixWorld).invert()
: new Matrix4().identity()

const callback = (child: Entity) => {
const obj = getOptionalComponent(child, MeshComponent)
if (obj) expandBoxByObject(obj, box)
if (obj) {
expandBoxByObject(obj, box, entityMatrixInverse)
expandBoxByObject(obj, worldBox)
}
}

iterateEntityNode(entity, callback)
Expand All @@ -135,22 +148,35 @@ export const updateBoundingBox = (entity: Entity) => {
if (!helperEntity) return

const helperObject = getComponent(helperEntity, ObjectComponent) as any as Box3Helper

helperObject.box.copy(box)
helperObject.updateMatrixWorld(true)
helperObject.position.set(0, 0, 0)
}

const _box = new Box3()
const _relativeMatrix = new Matrix4()

const expandBoxByObject = (object: Mesh<BufferGeometry>, box: Box3) => {
const expandBoxByObject = (object: Mesh<BufferGeometry>, box: Box3, entityMatrixInverse?: Matrix4) => {
const geometry = object.geometry
if (!geometry) return

if (geometry.boundingBox === null) {
geometry.computeBoundingBox()
}

object.updateMatrixWorld(true)

_box.copy(geometry.boundingBox!)
_box.applyMatrix4(object.matrixWorld)

if (entityMatrixInverse) {
// Transform to local space
_relativeMatrix.multiplyMatrices(entityMatrixInverse, object.matrixWorld)
_box.applyMatrix4(_relativeMatrix)
} else {
// Keep in world space
_box.applyMatrix4(object.matrixWorld)
}

box.union(_box)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/spatial/src/transform/systems/TransformSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ const execute = () => {
_frustum.setFromProjectionMatrix(_projScreenMatrix)

for (const entity of frustumCulledQuery()) {
const boundingBox = getOptionalComponent(entity, BoundingBoxComponent)?.box
const boundingBox = getOptionalComponent(entity, BoundingBoxComponent)?.worldBox

const shouldNotCull = boundingBox
? _frustum.intersectsBox(boundingBox)
: _frustum.containsPoint(TransformComponent.getWorldPosition(entity, _worldPos))
Expand Down
Loading
0