Skip to content

Commit

Permalink
perf(editor): optimize picking
Browse files Browse the repository at this point in the history
now first check bounding box;
now check picking only when point down;
  • Loading branch information
yyc-git committed Mar 8, 2024
1 parent eea8d33 commit 32bd886
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 20 deletions.
30 changes: 22 additions & 8 deletions doc/jiehuo.org
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -42,16 +42,30 @@ 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




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

Expand Down
6 changes: 3 additions & 3 deletions packages/interact/extensions/meta3d-interact/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions utils/meta3d-scenegraph-converter-three-utils/src/Classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -970,6 +971,7 @@ export class BufferGeometry extends EventDispatcher {
private _tangentAttribute: nullable<BufferAttributeType>
private _indexAttribute: BufferAttributeType
private _boundingSphere: SphereType
private _boundingBox: Box3Type

public uuid: string
public id: number
Expand All @@ -993,7 +995,7 @@ export class BufferGeometry extends EventDispatcher {
}

public get boundingBox(): nullable<Box3Type> {
return null
return this._boundingBox
}

public get index(): nullable<BufferAttributeType> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
Sphere,
Box3,
Vector3,
BufferAttribute
} from "three";
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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++) {

Expand All @@ -102,12 +103,77 @@ 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.');

}

}


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
}

0 comments on commit 32bd886

Please sign in to comment.