diff --git a/doc/jiehuo.org b/doc/jiehuo.org index dd3843515..8c42b0ee9 100755 --- a/doc/jiehuo.org +++ b/doc/jiehuo.org @@ -1,23 +1,23 @@ -* TODO add interact package +* DONE add interact package TODO add Input, Picking -* TODO update scenegraph +* DONE update scenegraph -* TODO gameview-render add OutlinePass +* DONE gameview-render add OutlinePass -* TODO gameview-render add related api +* DONE gameview-render add related api -* TODO update scenegraph +* DONE update scenegraph -* TODO script interact api +* DONE script interact api * DONE publish and update @@ -31,7 +31,7 @@ TODO add Input, Picking TODO add getViewRect, setSelectionObjects to script api -** TODO show outline +** DONE show outline TODO fix: select one but select all @@ -42,7 +42,7 @@ select one but select all children gameObject can't be select -add cube when run->event not work +add cube when run->event not work in gameview @@ -50,8 +50,22 @@ add cube when run->event not work TODO test glb model +** DONE too slow + +TODO optimize: +should first check bounding + +get geometry + +check only when trigger event + + ** TODO pass publish engine +* TODO fix: cancel load glb +* TODO fix: when stop, script asset->event file str not restore immdiatlly + + * TODO need update diff --git a/packages/interact/extensions/meta3d-interact/src/Main.ts b/packages/interact/extensions/meta3d-interact/src/Main.ts index ad72fe679..804dfda2e 100755 --- a/packages/interact/extensions/meta3d-interact/src/Main.ts +++ b/packages/interact/extensions/meta3d-interact/src/Main.ts @@ -306,11 +306,11 @@ let _raycastMesh = ( // test with bounding box in local space - // if (geometry.boundingBox !== null) { + if (geometry.boundingBox !== null) { - // if (_ray.intersectsBox(geometry.boundingBox) === false) return; + if (_ray.intersectsBox(geometry.boundingBox) === false) return; - // } + } // test for intersections with geometry diff --git a/utils/meta3d-scenegraph-converter-three-utils/src/Classes.ts b/utils/meta3d-scenegraph-converter-three-utils/src/Classes.ts index 629303fd9..1fff84986 100755 --- a/utils/meta3d-scenegraph-converter-three-utils/src/Classes.ts +++ b/utils/meta3d-scenegraph-converter-three-utils/src/Classes.ts @@ -47,7 +47,7 @@ import { EventDispatcher } from "./three/EventDispatcher"; import { filter, htmlImageElement, texture, wrap } from "meta3d-texture-basicsource-protocol/src/state/StateType"; import { color, directionLight } from "meta3d-component-directionlight-protocol"; import { - BufferAttribute, Color, FrontSide, Layers, Matrix3, Matrix4, NoBlending, Sphere, Vector3, Quaternion, Source, + BufferAttribute, Color, FrontSide, Layers, Matrix3, Matrix4, NoBlending, Sphere, Box3, Vector3, Quaternion, Source, ClampToEdgeWrapping, RepeatWrapping, MirroredRepeatWrapping, @@ -72,7 +72,7 @@ import { } from "./SetVariables"; import * as Meta3DCameraController from "meta3d-gltf-extensions/src/Meta3DCameraController" import * as Meta3DScript from "meta3d-gltf-extensions/src/Meta3DScript" -import { computeBoundingSphere } from "./utils/BoundingUtils"; +import { computeBoundingBox, computeBoundingSphere } from "./utils/BoundingUtils"; let _getEmptyGameObject = () => -1 @@ -961,6 +961,7 @@ export class BufferGeometry extends EventDispatcher { // TODO perf: get from collider component this._boundingSphere = computeBoundingSphere(new Sphere(), this._positionAttribute, new Vector3()) + this._boundingBox = computeBoundingBox(new Box3(), this._positionAttribute) } private _geometry: geometry @@ -970,6 +971,7 @@ export class BufferGeometry extends EventDispatcher { private _tangentAttribute: nullable private _indexAttribute: BufferAttributeType private _boundingSphere: SphereType + private _boundingBox: Box3Type public uuid: string public id: number @@ -993,7 +995,7 @@ export class BufferGeometry extends EventDispatcher { } public get boundingBox(): nullable { - return null + return this._boundingBox } public get index(): nullable { diff --git a/utils/meta3d-scenegraph-converter-three-utils/src/SetThreeObjects.ts b/utils/meta3d-scenegraph-converter-three-utils/src/SetThreeObjects.ts index 0612a6f5f..d4574926c 100755 --- a/utils/meta3d-scenegraph-converter-three-utils/src/SetThreeObjects.ts +++ b/utils/meta3d-scenegraph-converter-three-utils/src/SetThreeObjects.ts @@ -1,7 +1,7 @@ import { service as threeAPIService } from "meta3d-three-api-protocol/src/service/ServiceType" import { state as meta3dState, getExtensionService as getExtensionServiceMeta3D, createExtensionState as createExtensionStateMeta3D, getExtensionLife as getLifeMeta3D, extensionLife, api } from "meta3d-type" -export let BufferAttribute: any, Color: any, FrontSide: any, Layers: any, Matrix3: any, Matrix4: any, NoBlending: any, Sphere: any, Vector3: any, Quaternion: any, Source: any, +export let BufferAttribute: any, Color: any, FrontSide: any, Layers: any, Matrix3: any, Matrix4: any, NoBlending: any, Sphere: any, Box3: any, Vector3: any, Quaternion: any, Source: any, ClampToEdgeWrapping: any, RepeatWrapping: any, MirroredRepeatWrapping: any, @@ -28,6 +28,7 @@ export let setThreeObjects = (api: api, meta3dState: meta3dState) => { Matrix4 = threeAPIService.Matrix4 NoBlending = threeAPIService.NoBlending Sphere = threeAPIService.Sphere + Box3 = threeAPIService.Box3 Vector3 = threeAPIService.Vector3 Quaternion = threeAPIService.Quaternion Source = threeAPIService.Source diff --git a/utils/meta3d-scenegraph-converter-three-utils/src/utils/BoundingUtils.ts b/utils/meta3d-scenegraph-converter-three-utils/src/utils/BoundingUtils.ts index f54a98a91..9fdf8bf8e 100644 --- a/utils/meta3d-scenegraph-converter-three-utils/src/utils/BoundingUtils.ts +++ b/utils/meta3d-scenegraph-converter-three-utils/src/utils/BoundingUtils.ts @@ -1,5 +1,6 @@ import type { Sphere, + Box3, Vector3, BufferAttribute } from "three"; @@ -8,9 +9,9 @@ export let computeBoundingSphere = (boundingSphere: Sphere, position: BufferAttr // const _vector = /*@__PURE__*/ new Vector3(); if (position && position.isGLBufferAttribute) { - // console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this ); + // console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', ; - // this.boundingSphere.set( new Vector3(), Infinity ); + // boundingSphere.set( new Vector3(), Infinity ); // return; @@ -35,7 +36,7 @@ export let computeBoundingSphere = (boundingSphere: Sphere, position: BufferAttr // const morphAttribute = morphAttributesPosition[i]; // _boxMorphTargets.setFromBufferAttribute(morphAttribute); - // if (this.morphTargetsRelative) { + // if (morphTargetsRelative) { // _vector.addVectors(_box.min, _boxMorphTargets.min); // _box.expandByPoint(_vector); @@ -77,7 +78,7 @@ export let computeBoundingSphere = (boundingSphere: Sphere, position: BufferAttr // for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { // const morphAttribute = morphAttributesPosition[i]; - // const morphTargetsRelative = this.morphTargetsRelative; + // const morphTargetsRelative = morphTargetsRelative; // for (let j = 0, jl = morphAttribute.count; j < jl; j++) { @@ -102,7 +103,7 @@ export let computeBoundingSphere = (boundingSphere: Sphere, position: BufferAttr if (isNaN(boundingSphere.radius)) { - console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this); + console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.'); } @@ -110,4 +111,69 @@ export let computeBoundingSphere = (boundingSphere: Sphere, position: BufferAttr return boundingSphere +} + +export let computeBoundingBox = (boundingBox: Box3, position: BufferAttribute | any) => { + // const position = attributes.position; + // const morphAttributesPosition = morphAttributes.position; + + if (position && position.isGLBufferAttribute) { + + // console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false"'); + + // boundingBox.set( + // new Vector3(- Infinity, - Infinity, - Infinity), + // new Vector3(+ Infinity, + Infinity, + Infinity) + // ); + + // return; + throw new Error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false"'); + + } + + if (position !== undefined) { + + boundingBox.setFromBufferAttribute(position); + + // process morph attributes if present + + // if (morphAttributesPosition) { + + // for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { + + // const morphAttribute = morphAttributesPosition[i]; + // _box.setFromBufferAttribute(morphAttribute); + + // if (morphTargetsRelative) { + + // _vector.addVectors(boundingBox.min, _box.min); + // boundingBox.expandByPoint(_vector); + + // _vector.addVectors(boundingBox.max, _box.max); + // boundingBox.expandByPoint(_vector); + + // } else { + + // boundingBox.expandByPoint(_box.min); + // boundingBox.expandByPoint(_box.max); + + // } + + // } + + // } + + } else { + + boundingBox.makeEmpty(); + + } + + if (isNaN(boundingBox.min.x) || isNaN(boundingBox.min.y) || isNaN(boundingBox.min.z)) { + + console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.'); + + } + + return boundingBox } \ No newline at end of file