From c47257c47d65c1e5c3ee4f0eae0b2bf42295561c Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Thu, 11 Jul 2024 10:15:57 +0800 Subject: [PATCH 1/9] fix(PCF): PCF shadow error (#371) --- src/assets/shader/materials/program/ShadowMapping_frag.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/assets/shader/materials/program/ShadowMapping_frag.ts b/src/assets/shader/materials/program/ShadowMapping_frag.ts index eb28f8a2..15989190 100644 --- a/src/assets/shader/materials/program/ShadowMapping_frag.ts +++ b/src/assets/shader/materials/program/ShadowMapping_frag.ts @@ -173,7 +173,8 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` } } } - shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0); + } + shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0); #endif #if USE_SOFT_SHADOW From c79e2878c61480583ea4a73188e0e81c395d0dcb Mon Sep 17 00:00:00 2001 From: hellmor Date: Mon, 15 Jul 2024 23:47:15 +0800 Subject: [PATCH 2/9] fix(MeshRenderer): replace geometry error (#415) * Fix: error when replace the geometry of MeshRenderer. * chore: remove log in loaderbase --------- Co-authored-by: ShuangLiu --- samples/geometry/Sample_ReplaceGeometry.ts | 73 ++++++++++++++++++++++ src/components/renderer/MeshRenderer.ts | 32 ++++++---- src/components/renderer/RenderNode.ts | 12 +++- src/loader/LoaderBase.ts | 2 +- 4 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 samples/geometry/Sample_ReplaceGeometry.ts diff --git a/samples/geometry/Sample_ReplaceGeometry.ts b/samples/geometry/Sample_ReplaceGeometry.ts new file mode 100644 index 00000000..99f4fd24 --- /dev/null +++ b/samples/geometry/Sample_ReplaceGeometry.ts @@ -0,0 +1,73 @@ +import { BoxGeometry, Engine3D, GeometryBase, LitMaterial, MeshRenderer, Object3D, Object3DUtil, Scene3D, SphereGeometry, TorusGeometry, Vector3 } from "@orillusion/core"; +import { createExampleScene, createSceneParam } from "@samples/utils/ExampleScene"; +import { GUIHelp } from "@orillusion/debug/GUIHelp"; + +// An sample to replace geometry of meshRenderer +class Sample_ReplaceGeometry { + scene: Scene3D; + geometries: GeometryBase[]; + renderer: MeshRenderer; + index = 0; + async run() { + let param = createSceneParam(); + param.light.intensity = 1; + param.camera.distance = 40; + await Engine3D.init(); + let exampleScene = createExampleScene(param); + + Engine3D.setting.shadow.shadowBound = 100; + Engine3D.setting.shadow.shadowSize = 2048; + Engine3D.setting.shadow.shadowBias = 0.04; + + this.scene = exampleScene.scene; + + Engine3D.startRenderView(exampleScene.view); + + + GUIHelp.init(); + this.initGeometries(); + + let duck = await (await Engine3D.res.loadGltf('PBR/Duck/Duck.gltf')) as Object3D; + let duckGeometry = duck.getComponents(MeshRenderer)[0].geometry; + this.geometries.push(duckGeometry); + + this.initRenderer(); + let scale = new Vector3(1, 1, 1); + GUIHelp.add(this, 'index', 0, 4, 1).onChange((value) => { + this.renderer.geometry = this.geometries[value]; + if (value == this.geometries.length - 1) { + scale.set(0.03, 0.03, 0.03); + } else { + scale.set(1, 1, 1); + } + this.renderer.object3D.localScale = scale; + }) + + GUIHelp.open(); + this.initFloor(); + } + + initFloor() { + let floorHeight = 20; + let floor = Object3DUtil.GetSingleCube(1000, floorHeight, 1000, 0.5, 0.5, 0.5); + floor.y = -floorHeight; + this.scene.addChild(floor); + } + + initGeometries() { + this.geometries = []; + this.geometries.push(new SphereGeometry(2, 20, 20)); + this.geometries.push(new BoxGeometry(2, 8, 4)); + this.geometries.push(new TorusGeometry(2, 0.4)); + } + + initRenderer() { + let obj = new Object3D(); + this.renderer = obj.addComponent(MeshRenderer); + this.renderer.material = new LitMaterial(); + this.renderer.geometry = this.geometries[0]; + this.scene.addChild(obj); + } +} + +new Sample_ReplaceGeometry().run(); \ No newline at end of file diff --git a/src/components/renderer/MeshRenderer.ts b/src/components/renderer/MeshRenderer.ts index 09ebb88b..8208f7eb 100644 --- a/src/components/renderer/MeshRenderer.ts +++ b/src/components/renderer/MeshRenderer.ts @@ -57,25 +57,31 @@ export class MeshRenderer extends RenderNode { public set geometry(value: GeometryBase) { //this must use super geometry has reference in super super.geometry = value; - let isMorphTarget = value.morphTargetDictionary != null; - if (isMorphTarget) { - this.morphData ||= new MorphTargetData(); - this.morphData.morphTargetsRelative = value.morphTargetsRelative; - this.morphData.initMorphTarget(value); - } - this.morphData && (this.morphData.enable = isMorphTarget); - if (this.morphData && this.morphData.enable) { - this.addRendererMask(RendererMask.MorphTarget); + if (value) { + let isMorphTarget = value.morphTargetDictionary != null; + if (isMorphTarget) { + this.morphData ||= new MorphTargetData(); + this.morphData.morphTargetsRelative = value.morphTargetsRelative; + this.morphData.initMorphTarget(value); + } + this.morphData && (this.morphData.enable = isMorphTarget); + if (this.morphData?.enable) { + this.addRendererMask(RendererMask.MorphTarget); + } else { + this.removeRendererMask(RendererMask.MorphTarget); + } + + this.object3D.bound = this._geometry.bounds.clone(); } else { + if (this.morphData) { + this.morphData.enable = false; + } this.removeRendererMask(RendererMask.MorphTarget); - // this.onCompute = null; } - - this.object3D.bound = this._geometry.bounds.clone(); if (!this._readyPipeline) { this.initPipeline(); - if (this._computes && this._computes) { + if (this._computes) { this.onCompute = mergeFunctions(this.onCompute, () => { for (let i = 0; i < this._computes.length; i++) { const compute = this._computes[i]; diff --git a/src/components/renderer/RenderNode.ts b/src/components/renderer/RenderNode.ts index 194485f6..7985d991 100644 --- a/src/components/renderer/RenderNode.ts +++ b/src/components/renderer/RenderNode.ts @@ -123,10 +123,14 @@ export class RenderNode extends ComponentBase { public set geometry(value: GeometryBase) { if (this._geometry != value) { + this._readyPipeline = false; + if (this._geometry) { Reference.getInstance().detached(this._geometry, this) } - Reference.getInstance().attached(value, this) + if (value) { + Reference.getInstance().attached(value, this) + } } this._geometry = value; } @@ -258,7 +262,6 @@ export class RenderNode extends ComponentBase { protected initPipeline() { if (this._geometry && this._materials.length > 0) { - let index = 0; for (let j = 0; j < this._materials.length; j++) { const material = this._materials[j]; let passList = material.getPass(PassType.COLOR); @@ -274,7 +277,6 @@ export class RenderNode extends ComponentBase { } this._readyPipeline = true; - let transparent = false; let sort = 0; for (let i = 0; i < this.materials.length; i++) { const element = this.materials[i]; @@ -364,6 +366,8 @@ export class RenderNode extends ComponentBase { } public renderPass(view: View3D, passType: PassType, renderContext: RenderContext) { + if (!this._geometry) + return; let renderNode = this; let worldMatrix = renderNode.transform._worldMatrix; for (let i = 0; i < renderNode.materials.length; i++) { @@ -433,6 +437,8 @@ export class RenderNode extends ComponentBase { if (!this.enable) return; // this.nodeUpdate(view, passType, rendererPassState, clusterLightingBuffer); + if (!this._geometry) + return; let node = this; let worldMatrix = node.object3D.transform._worldMatrix; diff --git a/src/loader/LoaderBase.ts b/src/loader/LoaderBase.ts index 3cdf6393..b27c748e 100644 --- a/src/loader/LoaderBase.ts +++ b/src/loader/LoaderBase.ts @@ -155,7 +155,7 @@ export class LoaderBase { } if (receivedArr.length > 0) { for (let i = 0; i < chunks.length; i++) { - console.log(receivedArr[i]); + // console.log(receivedArr[i]); if (loaderFunctions && loaderFunctions.onProgress) { loaderFunctions.onProgress.call(this, receivedArr[i], receivedLength, url); } From 55484676627198c1b646c3944f4077e0b639adb0 Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Tue, 16 Jul 2024 00:23:23 +0800 Subject: [PATCH 3/9] fix(pickfire): fix undefined values (#416) 1. assign values with input event 2. simplify event.data with {worldPos, screenUv, meshID, worldNormal} --- src/io/PickFire.ts | 51 +++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/io/PickFire.ts b/src/io/PickFire.ts index 04b5d0f4..e88cd326 100644 --- a/src/io/PickFire.ts +++ b/src/io/PickFire.ts @@ -103,12 +103,10 @@ export class PickFire extends CEventDispatcher { let target = this.findNearestObj(this._interestList, this._view.camera); this._lastDownTarget = target; if (target) { + Object.assign(this._downEvent, e); + this._downEvent.type = PointerEvent3D.PICK_DOWN; this._downEvent.target = target.object3D; - this._downEvent.ctrlKey = e.ctrlKey; - this._downEvent.metaKey = e.metaKey; - this._downEvent.altKey = e.altKey; - this._downEvent.shiftKey = e.shiftKey; - this._downEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode }; + this._downEvent.data = this.getPickInfo(); this.dispatchEvent(this._downEvent); if (target.object3D.containEventListener(PointerEvent3D.PICK_DOWN)) { @@ -125,13 +123,12 @@ export class PickFire extends CEventDispatcher { this.pick(this._view.camera); let target = this.findNearestObj(this._interestList, this._view.camera); if (target) { + Object.assign(this._upEvent, e); + this._upEvent.type = PointerEvent3D.PICK_UP; this._upEvent.target = target.object3D; - this._upEvent.ctrlKey = e.ctrlKey; - this._upEvent.metaKey = e.metaKey; - this._upEvent.altKey = e.altKey; - this._upEvent.shiftKey = e.shiftKey; - this._upEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode }; + this._upEvent.data = this.getPickInfo(); this.dispatchEvent(this._upEvent); + if (target.object3D.containEventListener(PointerEvent3D.PICK_UP)) { target.object3D.dispatchEvent(this._upEvent); } @@ -156,13 +153,12 @@ export class PickFire extends CEventDispatcher { this.pick(this._view.camera); let target = this.findNearestObj(this._interestList, this._view.camera); if (target) { + Object.assign(this._mouseMove, e); + this._mouseMove.type = PointerEvent3D.PICK_MOVE; this._mouseMove.target = target.object3D; - this._mouseMove.ctrlKey = e.ctrlKey; - this._mouseMove.metaKey = e.metaKey; - this._mouseMove.altKey = e.altKey; - this._mouseMove.shiftKey = e.shiftKey; - this._mouseMove.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode }; + this._mouseMove.data = this.getPickInfo(); this.dispatchEvent(this._mouseMove); + if (target.object3D.containEventListener(PointerEvent3D.PICK_MOVE)) { target.object3D.dispatchEvent(this._mouseMove); } @@ -170,24 +166,21 @@ export class PickFire extends CEventDispatcher { if (target != this._lastFocus) { if (this._lastFocus && this._lastFocus.object3D) { + Object.assign(this._outEvent, e); + this._outEvent.type = PointerEvent3D.PICK_OUT; this._outEvent.target = this._lastFocus.object3D; - this._outEvent.data = { pick: this._lastFocus, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode }; - this._outEvent.ctrlKey = e.ctrlKey; - this._outEvent.metaKey = e.metaKey; - this._outEvent.altKey = e.altKey; - this._outEvent.shiftKey = e.shiftKey; + this._outEvent.data = this.getPickInfo(); this.dispatchEvent(this._outEvent); + if (this._lastFocus.object3D.containEventListener(PointerEvent3D.PICK_OUT)) { this._lastFocus.object3D.dispatchEvent(this._outEvent); } } if (target) { + Object.assign(this._overEvent, e); + this._overEvent.type = PointerEvent3D.PICK_OVER; this._overEvent.target = target.object3D; - this._overEvent.ctrlKey = e.ctrlKey; - this._overEvent.metaKey = e.metaKey; - this._overEvent.altKey = e.altKey; - this._overEvent.shiftKey = e.shiftKey; - this._overEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode }; + this._overEvent.data = this.getPickInfo(); this.dispatchEvent(this._overEvent); if (target.object3D.containEventListener(PointerEvent3D.PICK_OVER)) { target.object3D.dispatchEvent(this._overEvent); @@ -204,12 +197,10 @@ export class PickFire extends CEventDispatcher { let target = this.findNearestObj(this._interestList, this._view.camera); if (target) { let info = Engine3D.setting.pick.mode == `pixel` ? this.getPickInfo() : null; + Object.assign(this._pickEvent, e); + this._pickEvent.type = PointerEvent3D.PICK_CLICK; this._pickEvent.target = target.object3D; - this._pickEvent.ctrlKey = e.ctrlKey; - this._pickEvent.metaKey = e.metaKey; - this._pickEvent.altKey = e.altKey; - this._pickEvent.shiftKey = e.shiftKey; - this._pickEvent.data = { pick: target, pickInfo: info, mouseCode: this._mouseCode }; + this._pickEvent.data = info; this.dispatchEvent(this._pickEvent); if (target === this._lastDownTarget && target.object3D.containEventListener(PointerEvent3D.PICK_CLICK)) { From 6704de6bac0d24114f4d9659a4d947e498fb7dbc Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Tue, 16 Jul 2024 21:28:30 +0800 Subject: [PATCH 4/9] chore: update public --- public | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public b/public index 1df88087..61cff389 160000 --- a/public +++ b/public @@ -1 +1 @@ -Subproject commit 1df8808704217ad22f1baa6dfb21a0ce6cc5c0e3 +Subproject commit 61cff389761990a774d61812ce81bf3be4a4882c From b248c455c428edc4b4c7233d39c6449e31322b12 Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Tue, 16 Jul 2024 22:14:18 +0800 Subject: [PATCH 5/9] fix(pick): fix right click (#418) --- samples/compute/Sample_Fluid.ts | 2 +- samples/compute/Sample_FluidOptimize.ts | 2 +- samples/lights/Sample_MovebleLight.ts | 4 +-- samples/pick/Sample_BoxColliderPick.ts | 7 ++--- samples/pick/Sample_MeshColliderPick.ts | 7 ++--- src/event/eventConst/PointerEvent3D.ts | 6 ++-- src/io/InputSystem.ts | 40 ++++++++----------------- src/io/PickFire.ts | 2 ++ 8 files changed, 27 insertions(+), 43 deletions(-) diff --git a/samples/compute/Sample_Fluid.ts b/samples/compute/Sample_Fluid.ts index 20927dbb..bd095d15 100644 --- a/samples/compute/Sample_Fluid.ts +++ b/samples/compute/Sample_Fluid.ts @@ -54,7 +54,7 @@ export class Demo_Fluid { pickFire.addEventListener( PointerEvent3D.PICK_MOVE, function (e: PointerEvent3D) { - let point = e.data.pickInfo.worldPos; + let point = e.data.worldPos; if (point.y >= 0 && (this.mLastPoint.x != point.x && this.mLastPoint.y != point.y && this.mLastPoint.z != point.z)) { point.subtract(this.mLastPoint, this.mVelocity); this.mLastPoint.copy(point); diff --git a/samples/compute/Sample_FluidOptimize.ts b/samples/compute/Sample_FluidOptimize.ts index 6ea52000..b39afbbc 100644 --- a/samples/compute/Sample_FluidOptimize.ts +++ b/samples/compute/Sample_FluidOptimize.ts @@ -53,7 +53,7 @@ export class Demo_FluidOptimize { pickFire.addEventListener( PointerEvent3D.PICK_MOVE, function (e: PointerEvent3D) { - let point = e.data.pickInfo.worldPos; + let point = e.data.worldPos; if (point.y >= 0 && (this.mLastPoint.x != point.x && this.mLastPoint.y != point.y && this.mLastPoint.z != point.z)) { try{ point.subtract(this.mLastPoint, this.mVelocity); diff --git a/samples/lights/Sample_MovebleLight.ts b/samples/lights/Sample_MovebleLight.ts index 32bb046d..ca1216e6 100644 --- a/samples/lights/Sample_MovebleLight.ts +++ b/samples/lights/Sample_MovebleLight.ts @@ -97,8 +97,8 @@ class Sample_MovebleLight { } private onMove(e: PointerEvent3D) { //set pick position as light position - this.light.transform.x = e.data.pickInfo.worldPos.x; - this.light.transform.y = e.data.pickInfo.worldPos.y; + this.light.transform.x = e.data.worldPos.x; + this.light.transform.y = e.data.worldPos.y; } } //rotate component diff --git a/samples/pick/Sample_BoxColliderPick.ts b/samples/pick/Sample_BoxColliderPick.ts index a457d3c8..ef1db0cf 100644 --- a/samples/pick/Sample_BoxColliderPick.ts +++ b/samples/pick/Sample_BoxColliderPick.ts @@ -54,10 +54,9 @@ class Sample_BoxColliderPick { } private onMousePick(e: PointerEvent3D) { - let pick = e.data.pick; - if (pick && pick.object3D) { - let obj = pick.object3D; - let meshRenderer = obj.getComponent(MeshRenderer); + let pick = e.target; + if (pick) { + let meshRenderer = pick.getComponent(MeshRenderer); //modify base color meshRenderer.material.baseColor = new Color(Math.random(), Math.random(), Math.random()) } diff --git a/samples/pick/Sample_MeshColliderPick.ts b/samples/pick/Sample_MeshColliderPick.ts index 7395881c..6b93692b 100644 --- a/samples/pick/Sample_MeshColliderPick.ts +++ b/samples/pick/Sample_MeshColliderPick.ts @@ -55,10 +55,9 @@ class Sample_MeshColliderPick { } private onMousePick(e: PointerEvent3D) { - let pick = e.data.pick; - if (pick && pick.object3D) { - let obj = pick.object3D; - let meshRenderer = obj.getComponent(MeshRenderer); + let pick = e.target; + if (pick) { + let meshRenderer = pick.getComponent(MeshRenderer); //modify base color meshRenderer.material.baseColor = new Color(Math.random(), Math.random(), Math.random()) } diff --git a/src/event/eventConst/PointerEvent3D.ts b/src/event/eventConst/PointerEvent3D.ts index ce31bdf8..38f56e90 100644 --- a/src/event/eventConst/PointerEvent3D.ts +++ b/src/event/eventConst/PointerEvent3D.ts @@ -66,17 +66,17 @@ export class PointerEvent3D extends CEvent { * * Triggered when the right pointer clicked */ - static POINTER_RIGHT_CLICK: string = 'onPointerRightClick'; + public static POINTER_RIGHT_CLICK: string = 'onPointerRightClick'; /** * * Triggered when the middle pointer released */ - static POINTER_MID_UP: string = 'onPointerMidUp'; + public static POINTER_MID_UP: string = 'onPointerMidUp'; /** * * Triggered when the middle pointer pressed */ - static POINTER_MID_DOWN: string = 'onPointerMidDown'; + public static POINTER_MID_DOWN: string = 'onPointerMidDown'; /** * Triggered when the pointer clicked diff --git a/src/io/InputSystem.ts b/src/io/InputSystem.ts index d40fbb3b..64b9d1cf 100644 --- a/src/io/InputSystem.ts +++ b/src/io/InputSystem.ts @@ -95,40 +95,39 @@ export class InputSystem extends CEventDispatcher { */ public initCanvas(canvas: HTMLCanvasElement) { this.canvas = canvas; + // temp vars to check click + let _t = 0, _x = 0, _y = 0, _button = 0 + canvas.onpointerdown = (ev: PointerEvent) => { + _t = performance.now(); + _x = ev.clientX; + _y = ev.clientY; + _button = ev.button; - // canvas.onpointerdown = (ev: PointerEvent) => { - // if (ev.button == 0) { - // this.mouseStart(ev); - // } else if (ev.button == 1) { - // this.middleDown(ev); - // } else if (ev.button == 2) { - // this.mouseStart(ev); - // } - // } - - canvas.onmousedown = (ev: MouseEvent) => { if (ev.button == 0) { this.mouseStart(ev); } else if (ev.button == 1) { this.middleDown(ev); } else if (ev.button == 2) { + this.isRightMouseDown = true this.mouseStart(ev); } } - canvas.onpointerup = (ev: PointerEvent) => { if (ev.button == 0) { this.mouseEnd(ev); } else if (ev.button == 1) { this.middleUp(ev); } else if (ev.button == 2) { + this.isRightMouseDown = false this.mouseEnd(ev); } + if(ev.button === _button && performance.now() - _t < 300 && Math.abs(_x - ev.clientX) < 20 && Math.abs(_y - ev.clientY) < 20){ + ev.button === 0 ? this.mouseClick(ev) : this.rightClick(ev); + } } canvas.onpointerenter = (ev: PointerEvent) => { this.mouseOver(ev); } - canvas.onpointermove = (ev: PointerEvent) => { this.mouseMove(ev); } @@ -142,21 +141,6 @@ export class InputSystem extends CEventDispatcher { this.mouseEnd(ev); } - canvas.addEventListener( - 'click', - (e: MouseEvent) => { - //if right click - if (e.button == 2) { - this.isRightMouseDown = false; - this.rightClick(e); - } else if (e.button == 0) { - this.isMouseDown = false; - this.mouseClick(e); - } - }, - true, - ); - // let input = document.createElement(`input`); // input.setSelectionRange(-1000, 1000); // input.style.zIndex = `9999` diff --git a/src/io/PickFire.ts b/src/io/PickFire.ts index e88cd326..151ce3f5 100644 --- a/src/io/PickFire.ts +++ b/src/io/PickFire.ts @@ -74,6 +74,7 @@ export class PickFire extends CEventDispatcher { Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_DOWN, this.onTouchStart, this); Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_UP, this.onTouchEnd, this); Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_CLICK, this.onTouchOnce, this); + Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_RIGHT_CLICK, this.onTouchOnce, this); Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_MOVE, this.onTouchMove, this); } @@ -91,6 +92,7 @@ export class PickFire extends CEventDispatcher { Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_DOWN, this.onTouchStart, this); Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_UP, this.onTouchEnd, this); Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_CLICK, this.onTouchOnce, this); + Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_RIGHT_CLICK, this.onTouchOnce, this); Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_MOVE, this.onTouchMove, this); } From 61c7718aed73e5a8f33f30a44b1e5d1b7b75e183 Mon Sep 17 00:00:00 2001 From: JingwenBai <98864137+JingwenBai@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:32:48 +0100 Subject: [PATCH 6/9] docs(README): add contributors' samples #419 Co-authored-by: ShuangLiu --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index f162614a..2c398fc4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,30 @@ ## Need to know Beta version, **NOT** recommended for any commercial application. +## Contributing (ongoing) + +`WebGPU` is the latest technology in the web domain and will play a crucial role in terms of 3D rendering as well as `AI/LLM` scenarios. + +We aim to create a dedicated technical community for the `WebGPU` field, bringing together outstanding developers. + +Hope more and more `front-end` developers could stay updated with the latest Web technologies `NOT ONLY` image slicing for web design. + +Specifically, we will continuously update the excellent samples provided by open-source contributors, allowing everyone to see better works. + +Hope it could help highlight the very talented individual developers within the community! + + + + + + + + + + + + + ## Install ### NPM From 367f46904325e87b3f8a257d5cc3e44f96510132 Mon Sep 17 00:00:00 2001 From: Codeboy Date: Fri, 19 Jul 2024 04:12:03 +0800 Subject: [PATCH 7/9] fix(pick): fix gui pick events (#422) * chore: remove sample_candleflame maskMap * fix pick * fix(pick): fix gui pick over/out * fix: pickpick sample --------- Co-authored-by: ShuangLiu --- samples/compute/Sample_Fluid.ts | 2 +- samples/compute/Sample_FluidOptimize.ts | 16 ++--- samples/compute/fluid/FluidRenderShader.ts | 2 +- samples/compute/fluid/FluidRenderShaderOpt.ts | 1 + samples/pick/Sample_PixelPick.ts | 3 +- src/components/gui/GUIPick.ts | 66 ++++++++++++------- .../gui/uiComponents/IUIInteractive.ts | 4 +- src/components/gui/uiComponents/UIPanel.ts | 1 - src/io/PickFire.ts | 2 - 9 files changed, 58 insertions(+), 39 deletions(-) diff --git a/samples/compute/Sample_Fluid.ts b/samples/compute/Sample_Fluid.ts index bd095d15..0ad271ef 100644 --- a/samples/compute/Sample_Fluid.ts +++ b/samples/compute/Sample_Fluid.ts @@ -52,7 +52,7 @@ export class Demo_Fluid { obj.addComponent(ColliderComponent); let pickFire = scene.view.pickFire; pickFire.addEventListener( - PointerEvent3D.PICK_MOVE, + PointerEvent3D.PICK_MOVE, function (e: PointerEvent3D) { let point = e.data.worldPos; if (point.y >= 0 && (this.mLastPoint.x != point.x && this.mLastPoint.y != point.y && this.mLastPoint.z != point.z)) { diff --git a/samples/compute/Sample_FluidOptimize.ts b/samples/compute/Sample_FluidOptimize.ts index b39afbbc..016995e4 100644 --- a/samples/compute/Sample_FluidOptimize.ts +++ b/samples/compute/Sample_FluidOptimize.ts @@ -51,18 +51,18 @@ export class Demo_FluidOptimize { obj.addComponent(ColliderComponent); let pickFire = scene.view.pickFire; pickFire.addEventListener( - PointerEvent3D.PICK_MOVE, + PointerEvent3D.PICK_MOVE, function (e: PointerEvent3D) { let point = e.data.worldPos; if (point.y >= 0 && (this.mLastPoint.x != point.x && this.mLastPoint.y != point.y && this.mLastPoint.z != point.z)) { - try{ - point.subtract(this.mLastPoint, this.mVelocity); - this.mLastPoint.copy(point); - let r = scene.view.camera; - let ray = r.screenPointToRay(Engine3D.inputSystem.mouseX, Engine3D.inputSystem.mouseY); - emulation.updateInputInfo(scene.view.camera.transform.localPosition, ray.direction, this.mVelocity); + try { + point.subtract(this.mLastPoint, this.mVelocity); + this.mLastPoint.copy(point); + let r = scene.view.camera; + let ray = r.screenPointToRay(Engine3D.inputSystem.mouseX, Engine3D.inputSystem.mouseY); + emulation.updateInputInfo(scene.view.camera.transform.localPosition, ray.direction, this.mVelocity); } - catch(e){ + catch (e) { console.error(e); } diff --git a/samples/compute/fluid/FluidRenderShader.ts b/samples/compute/fluid/FluidRenderShader.ts index f4bd9d21..3ffb27ea 100644 --- a/samples/compute/fluid/FluidRenderShader.ts +++ b/samples/compute/fluid/FluidRenderShader.ts @@ -57,7 +57,7 @@ export let FluidRenderShader = /* wgsl */ ` //ORI_VertexOut.fragCoord = normalize(vertex.position.xy) + vec2(0.5, 0.5); ORI_VertexOut.varying_Color = particleColor[vertex.index]; ORI_VertexOut.varying_WNormal = worldNormal ; - + ORI_VertexOut.index = f32(particleGlobalData.instance_index) ; return ORI_VertexOut; } diff --git a/samples/compute/fluid/FluidRenderShaderOpt.ts b/samples/compute/fluid/FluidRenderShaderOpt.ts index 121a8865..68bec127 100644 --- a/samples/compute/fluid/FluidRenderShaderOpt.ts +++ b/samples/compute/fluid/FluidRenderShaderOpt.ts @@ -69,6 +69,7 @@ export let FluidRenderShaderOpt = /* wgsl */ ` ORI_VertexOut.varying_WPos = worldPos; ORI_VertexOut.varying_WPos.w = f32(particleGlobalData.instance_index); + ORI_VertexOut.index = f32(particleGlobalData.instance_index) ; var clipPosition = globalUniform.projMat * viewPosition ; diff --git a/samples/pick/Sample_PixelPick.ts b/samples/pick/Sample_PixelPick.ts index 40cbfb71..34277827 100644 --- a/samples/pick/Sample_PixelPick.ts +++ b/samples/pick/Sample_PixelPick.ts @@ -84,8 +84,7 @@ class Sample_PixelPick { } private getPickObject(e: PointerEvent3D): Object3D { - let pick = e.data.pick; - return pick ? pick.object3D : null; + return e.target || null; } private onMouseUp(e: PointerEvent3D) { diff --git a/src/components/gui/GUIPick.ts b/src/components/gui/GUIPick.ts index 1e55ddcd..2619b70a 100644 --- a/src/components/gui/GUIPick.ts +++ b/src/components/gui/GUIPick.ts @@ -4,7 +4,6 @@ import { MouseCode } from '../../event/MouseCode'; import { webGPUContext } from '../../gfx/graphics/webGpu/Context3D'; import { Ray } from '../../math/Ray'; import { Vector2 } from '../../math/Vector2'; -import { Vector3 } from '../../math/Vector3'; import { Time } from '../../util/Time'; import { IUIInteractive, UIInteractiveStyle } from './uiComponents/IUIInteractive'; import { UITransform } from './uiComponents/UITransform'; @@ -63,20 +62,37 @@ export class GUIPick { this._mouseCode = e.mouseCode; this.collectEntities(); let ret = this.pick(this._colliderOut); - ret && e.stopImmediatePropagation(); - let target = ret ? ret.collider : null; - if (target != this._lastOverTarget) { - if (this._lastOverTarget && this._lastOverTarget.enable) { + if(ret){ + e.stopImmediatePropagation(); + let _target = ret.collider; + if(_target != this._lastOverTarget){ + _target.mouseStyle = UIInteractiveStyle.OVER; + Object.assign(this._overEvent, e); + this._overEvent.type = PointerEvent3D.PICK_OVER_GUI; + this._overEvent.target = _target.object3D; + this._overEvent.data = ret; + _target.object3D.dispatchEvent(this._overEvent); + + if (this._lastOverTarget) { + this._lastOverTarget.mouseStyle = UIInteractiveStyle.NORMAL; + Object.assign(this._outEvent, e); + this._outEvent.type = PointerEvent3D.PICK_OUT_GUI; + this._outEvent.target = _target.object3D; + this._outEvent.data = ret; + this._lastOverTarget.object3D.dispatchEvent(this._outEvent); + } + } + this._lastOverTarget = _target; + }else{ + if (this._lastOverTarget) { this._lastOverTarget.mouseStyle = UIInteractiveStyle.NORMAL; - this._outEvent.data = this._lastOverTarget; + Object.assign(this._outEvent, e); + this._outEvent.type = PointerEvent3D.PICK_OUT_GUI; + this._outEvent.target = this._lastOverTarget.object3D; + this._outEvent.data = ret; this._lastOverTarget.object3D.dispatchEvent(this._outEvent); + this._lastOverTarget = null } - if (target) { - target.mouseStyle = UIInteractiveStyle.OVER; - this._overEvent.data = target; - target.object3D.dispatchEvent(this._overEvent); - } - this._lastOverTarget = target; } } @@ -94,13 +110,16 @@ export class GUIPick { this.collectEntities(); let ret = this.pick(this._colliderOut); ret && e.stopImmediatePropagation(); - let target = ret ? ret.collider : null; - if (target) { - target.mouseStyle = UIInteractiveStyle.DOWN; - this._overEvent.data = target; - target.object3D.dispatchEvent(this._overEvent); + let collider = ret ? ret.collider : null; + if (collider) { + collider.mouseStyle = UIInteractiveStyle.DOWN; + Object.assign(this._downEvent, e); + this._downEvent.type = PointerEvent3D.PICK_DOWN_GUI; + this._downEvent.target = collider.object3D; + this._downEvent.data = ret; + collider.object3D.dispatchEvent(this._downEvent); } - this._lastDownTarget = target; + this._lastDownTarget = collider; } private onTouchUp(e: PointerEvent3D) { @@ -111,17 +130,20 @@ export class GUIPick { let ret = this.pick(this._colliderOut); ret && e.stopImmediatePropagation(); - let target = ret ? ret.collider : null; + let collider = ret ? ret.collider : null; if (this._lastDownTarget && this._lastDownTarget.enable) { this._lastDownTarget.mouseStyle = UIInteractiveStyle.NORMAL; } - if (target && target == this._lastDownTarget) { + if (collider && collider == this._lastDownTarget) { if (Time.time - this._lastDownTime <= this._clickTimeSpan) { this._calcDistanceVec2.set(e.mouseX, e.mouseY); if (this._calcDistanceVec2.distance(this._lastDownPosition) <= this._clickDistanceSpan) { - this._clickEvent.data = { pick: target, pickInfo: ret, mouseCode: this._mouseCode }; - target.object3D.dispatchEvent(this._clickEvent); + Object.assign(this._clickEvent, e); + this._clickEvent.type = PointerEvent3D.PICK_CLICK_GUI; + this._clickEvent.target = collider.object3D; + this._clickEvent.data = ret; + collider.object3D.dispatchEvent(this._clickEvent); } } } diff --git a/src/components/gui/uiComponents/IUIInteractive.ts b/src/components/gui/uiComponents/IUIInteractive.ts index 7aeb785a..acc10cab 100644 --- a/src/components/gui/uiComponents/IUIInteractive.ts +++ b/src/components/gui/uiComponents/IUIInteractive.ts @@ -1,4 +1,4 @@ -import { CEventDispatcher } from "../../../event/CEventDispatcher"; +import { Object3D } from "../../../core/entities/Object3D"; import { Ray } from "../../../math/Ray"; import { Vector2 } from "../../../math/Vector2"; @@ -13,7 +13,7 @@ export interface IUIInteractive { interactive: boolean; enable: boolean; visible: boolean; - object3D?: CEventDispatcher; + object3D?: Object3D; get interactiveVisible(): boolean; diff --git a/src/components/gui/uiComponents/UIPanel.ts b/src/components/gui/uiComponents/UIPanel.ts index 5881529c..44a7d613 100644 --- a/src/components/gui/uiComponents/UIPanel.ts +++ b/src/components/gui/uiComponents/UIPanel.ts @@ -96,7 +96,6 @@ export class UIPanel extends UIImage { public set billboard(type: BillboardType) { if (this.space == GUISpace.View) { type = BillboardType.None; - } else { console.warn('Cannot enable billboard in view space'); } if (type == BillboardType.BillboardXYZ || type == BillboardType.BillboardY) { diff --git a/src/io/PickFire.ts b/src/io/PickFire.ts index 151ce3f5..d2a80a1b 100644 --- a/src/io/PickFire.ts +++ b/src/io/PickFire.ts @@ -55,7 +55,6 @@ export class PickFire extends CEventDispatcher { */ private init(): void { this.ray = new Ray(); - this.mouseEnableMap = new Map(); this._pickEvent = new PointerEvent3D(PointerEvent3D.PICK_CLICK); @@ -260,7 +259,6 @@ export class PickFire extends CEventDispatcher { } } - } } } From 7e4e15d1500d1e16e5a780123f78d602be9a9708 Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Fri, 19 Jul 2024 04:14:16 +0800 Subject: [PATCH 8/9] fix(doc): fix TextureCube order (#388) (#421) * fix(doc): fix TextureCube order * Update Res.ts * Update BitmapTextureCube.ts --- src/assets/Res.ts | 2 +- src/textures/BitmapTextureCube.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assets/Res.ts b/src/assets/Res.ts index 8e2b768c..b60f37ea 100644 --- a/src/assets/Res.ts +++ b/src/assets/Res.ts @@ -357,7 +357,7 @@ export class Res { /** * load texture data from array of web url. * make sure there are six images in a group, - * and the order is: nx, px, py, ny, nz, pz + * and the order is: [+X, -X, +Y, -Y, +Z, -Z] * @param urls */ public async loadTextureCubeMaps(urls: string[]) { diff --git a/src/textures/BitmapTextureCube.ts b/src/textures/BitmapTextureCube.ts index d6b254d3..efc43f68 100644 --- a/src/textures/BitmapTextureCube.ts +++ b/src/textures/BitmapTextureCube.ts @@ -167,7 +167,7 @@ export class BitmapTextureCube extends TextureCube { /** * load texture data from array of web url. * make sure there are six images in a group, - * and the order is: nx, px, py, ny, nz, pz + * and the order is: [+X, -X, +Y, -Y, +Z, -Z] * @param urls array of image url */ public async load(urls: string[]) { From 4706772ecd07f0ae7fbebdd614c51a32fc1f1ce4 Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Sun, 21 Jul 2024 14:06:58 +0800 Subject: [PATCH 9/9] bump v0.8.2 --- CHANGELOG.md | 17 +++++++++++++++++ package.json | 2 +- public | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebcef9ca..91c7ff7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## [0.8.2](https://github.com/Orillusion/orillusion/compare/v0.8.1...v0.8.2) (2024-07-21) + + +### Bug Fixes + +* **doc:** fix TextureCube order ([#388](https://github.com/Orillusion/orillusion/issues/388)) ([#421](https://github.com/Orillusion/orillusion/issues/421)) ([7e4e15d](https://github.com/Orillusion/orillusion/commit/7e4e15d1500d1e16e5a780123f78d602be9a9708)) +* **MeshRenderer:** replace geometry error ([#415](https://github.com/Orillusion/orillusion/issues/415)) ([c79e287](https://github.com/Orillusion/orillusion/commit/c79e2878c61480583ea4a73188e0e81c395d0dcb)) +* **PCF:** PCF shadow error ([#371](https://github.com/Orillusion/orillusion/issues/371)) ([c47257c](https://github.com/Orillusion/orillusion/commit/c47257c47d65c1e5c3ee4f0eae0b2bf42295561c)) +* **pick:** fix undefined values ([#416](https://github.com/Orillusion/orillusion/issues/416)) ([5548467](https://github.com/Orillusion/orillusion/commit/55484676627198c1b646c3944f4077e0b639adb0)) +* **pick:** fix gui pick events ([#422](https://github.com/Orillusion/orillusion/issues/422)) ([367f469](https://github.com/Orillusion/orillusion/commit/367f46904325e87b3f8a257d5cc3e44f96510132)) +* **pick:** fix right click ([#418](https://github.com/Orillusion/orillusion/issues/418)) ([b248c45](https://github.com/Orillusion/orillusion/commit/b248c455c428edc4b4c7233d39c6449e31322b12)) + + +### BREAKING CHANGES +* **PointerEvent3D:** simplified `event.data` with `{worldPos, screenUv, meshID, worldNormal}` + + ## [0.8.1](https://github.com/Orillusion/orillusion/compare/v0.7.2...v0.8.1) (2024-07-10) diff --git a/package.json b/package.json index 2f22284a..108885a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orillusion/core", - "version": "0.8.1", + "version": "0.8.2", "author": "Orillusion", "description": "Orillusion WebGPU Engine", "type": "module", diff --git a/public b/public index 61cff389..eeeaca67 160000 --- a/public +++ b/public @@ -1 +1 @@ -Subproject commit 61cff389761990a774d61812ce81bf3be4a4882c +Subproject commit eeeaca67f9ada0a09cc9d6fb93d3fe449bf4ff69