@needle-tools/engine 3.8.0-alpha → 3.9.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/needle-engine.js +222 -221
- package/dist/needle-engine.light.js +222 -221
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/codegen/register_types.js +2 -0
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_context.js +1 -1
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_element.js +15 -8
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_overlay.d.ts +2 -1
- package/lib/engine/engine_element_overlay.js +38 -55
- package/lib/engine/engine_element_overlay.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -1
- package/lib/engine-components/Renderer.js +14 -10
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RendererLightmap.d.ts +4 -6
- package/lib/engine-components/RendererLightmap.js +35 -25
- package/lib/engine-components/RendererLightmap.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +1 -0
- package/lib/engine-components/codegen/components.js +1 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +34 -30
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/USDZExporter.js +2 -0
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/USDZText.d.ts +2 -1
- package/lib/engine-components/export/usdz/extensions/USDZText.js +40 -3
- package/lib/engine-components/export/usdz/extensions/USDZText.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/USDZUI.d.ts +8 -0
- package/lib/engine-components/export/usdz/extensions/USDZUI.js +101 -0
- package/lib/engine-components/export/usdz/extensions/USDZUI.js.map +1 -0
- package/lib/engine-components/ui/Button.d.ts +1 -1
- package/lib/engine-components/ui/Button.js +4 -1
- package/lib/engine-components/ui/Button.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +2 -0
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components/ui/Graphic.js +3 -3
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.js +1 -1
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/codegen/register_types.js +2 -0
- package/src/engine/engine_context.ts +1 -1
- package/src/engine/engine_element.ts +15 -8
- package/src/engine/engine_element_overlay.ts +41 -52
- package/src/engine/extensions/extensions.ts +1 -1
- package/src/engine-components/Renderer.ts +19 -14
- package/src/engine-components/RendererLightmap.ts +36 -31
- package/src/engine-components/codegen/components.ts +1 -0
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +43 -37
- package/src/engine-components/export/usdz/USDZExporter.ts +2 -0
- package/src/engine-components/export/usdz/extensions/USDZText.ts +41 -1
- package/src/engine-components/export/usdz/extensions/USDZUI.ts +120 -0
- package/src/engine-components/ui/Button.ts +3 -1
- package/src/engine-components/ui/EventSystem.ts +3 -1
- package/src/engine-components/ui/Graphic.ts +3 -3
- package/src/engine-components/webxr/WebXR.ts +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IUSDExporterExtension } from "../Extension";
|
|
2
|
+
import { USDObject, USDZExporterContext } from "../ThreeUSDZExporter";
|
|
3
|
+
import { GameObject } from "../../../Component";
|
|
4
|
+
import { Canvas } from "../../../ui/Canvas";
|
|
5
|
+
import { CanvasGroup } from "../../../ui/CanvasGroup";
|
|
6
|
+
import { $shadowDomOwner } from "../../../ui/BaseUIComponent";
|
|
7
|
+
import { RectTransform } from "../../../ui/RectTransform";
|
|
8
|
+
import { Color, Mesh, MeshBasicMaterial, Object3D } from "three";
|
|
9
|
+
import { TextExtension } from "./USDZText";
|
|
10
|
+
import { RenderMode } from "../../../ui/Canvas";
|
|
11
|
+
|
|
12
|
+
export class USDZUIExtension implements IUSDExporterExtension {
|
|
13
|
+
get extensionName(): string {
|
|
14
|
+
return "tmui";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// TODO would probably be better to export each object instead of the entire Canvas
|
|
18
|
+
// so that we don't export them twice (once as regular hierarchy, once as part of Canvas export)
|
|
19
|
+
onExportObject(object: Object3D, model: USDObject, _context: USDZExporterContext) {
|
|
20
|
+
const canvas = GameObject.getComponent(object, Canvas);
|
|
21
|
+
|
|
22
|
+
if (canvas && canvas.activeAndEnabled && canvas.renderMode === RenderMode.WorldSpace) {
|
|
23
|
+
const textExt = new TextExtension();
|
|
24
|
+
const rt = GameObject.getComponent(object, RectTransform);
|
|
25
|
+
const canvasGroup = GameObject.getComponent(object, CanvasGroup);
|
|
26
|
+
|
|
27
|
+
let width = 100;
|
|
28
|
+
let height = 100;
|
|
29
|
+
if (rt) {
|
|
30
|
+
width = rt.width;
|
|
31
|
+
height = rt.height;
|
|
32
|
+
|
|
33
|
+
const shadowRootModel = USDObject.createEmpty();
|
|
34
|
+
const shadowComponent = rt.shadowComponent;
|
|
35
|
+
model.add(shadowRootModel);
|
|
36
|
+
|
|
37
|
+
if (shadowComponent) {
|
|
38
|
+
const mat = shadowComponent.matrix;
|
|
39
|
+
shadowRootModel.matrix.copy(mat);
|
|
40
|
+
// shadowRootModel.matrix.premultiply(invertX);
|
|
41
|
+
|
|
42
|
+
// TODO build map of parent GOs to USDObjects so we can reparent while traversing
|
|
43
|
+
const usdObjectMap = new Map<Object3D, USDObject>();
|
|
44
|
+
const opacityMap = new Map<Object3D, number>();
|
|
45
|
+
usdObjectMap.set(shadowComponent, shadowRootModel);
|
|
46
|
+
opacityMap.set(shadowComponent, canvasGroup ? canvasGroup.alpha : 1);
|
|
47
|
+
|
|
48
|
+
shadowComponent.traverse((child) => {
|
|
49
|
+
if (child === shadowComponent) return;
|
|
50
|
+
|
|
51
|
+
const childModel = USDObject.createEmpty();
|
|
52
|
+
childModel.matrix.copy(child.matrix);
|
|
53
|
+
|
|
54
|
+
const childParent = child.parent;
|
|
55
|
+
const isText = childParent && typeof childParent["textContent"] === "string" && childParent["textContent"].length;
|
|
56
|
+
let hierarchyOpacity = opacityMap.get(childParent!) || 1;
|
|
57
|
+
|
|
58
|
+
// TODO CanvasGroup doesn't render something but modifies opacity
|
|
59
|
+
// get CanvasGroup and modify alpha here
|
|
60
|
+
|
|
61
|
+
const canvasGroup = GameObject.getComponent(child, CanvasGroup);
|
|
62
|
+
if (canvasGroup)
|
|
63
|
+
hierarchyOpacity *= canvasGroup.alpha;
|
|
64
|
+
|
|
65
|
+
if (child instanceof Mesh && isText) {
|
|
66
|
+
// get shadoDomOwner so we can export Text from the text extension directly
|
|
67
|
+
const shadowDomOwner = child[$shadowDomOwner].gameObject;
|
|
68
|
+
textExt.exportText(shadowDomOwner, childModel, _context);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (child instanceof Mesh && !isText)
|
|
72
|
+
{
|
|
73
|
+
// UI behaves weird: it seems it's always flipped right now,
|
|
74
|
+
// and three magically fixes it when rendering
|
|
75
|
+
// see https://github.com/mrdoob/three.js/pull/12720#issue-275923930
|
|
76
|
+
// https://github.com/mrdoob/three.js/issues/17361
|
|
77
|
+
// So we need to fix the winding order after applying the negative scale.
|
|
78
|
+
const clonedGeo = child.geometry.clone();
|
|
79
|
+
clonedGeo.scale(1, 1, -1);
|
|
80
|
+
this.flipWindingOrder(clonedGeo);
|
|
81
|
+
childModel.geometry = clonedGeo;
|
|
82
|
+
|
|
83
|
+
const color = new Color();
|
|
84
|
+
const ownOpacity = child.material.opacity;
|
|
85
|
+
color.copy(child.material.color);
|
|
86
|
+
|
|
87
|
+
// Calculate opacity from parent chain and own alpha
|
|
88
|
+
childModel.material = new MeshBasicMaterial({
|
|
89
|
+
color: color,
|
|
90
|
+
opacity: ownOpacity * hierarchyOpacity,
|
|
91
|
+
map: child.material.map,
|
|
92
|
+
transparent: true,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
usdObjectMap.set(child, childModel);
|
|
97
|
+
opacityMap.set(child, hierarchyOpacity);
|
|
98
|
+
|
|
99
|
+
const parentUsdzObject = usdObjectMap.get(childParent!);
|
|
100
|
+
if (!parentUsdzObject) {
|
|
101
|
+
console.error("Error when exporting UI: shadow component parent not found!", child, child.parent);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
parentUsdzObject.add(childModel);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private flipWindingOrder(geometry) {
|
|
112
|
+
const index = geometry.index.array
|
|
113
|
+
for (let i = 0, il = index.length / 3; i < il; i++) {
|
|
114
|
+
let x = index[i * 3]
|
|
115
|
+
index[i * 3] = index[i * 3 + 2]
|
|
116
|
+
index[i * 3 + 2] = x
|
|
117
|
+
}
|
|
118
|
+
geometry.index.needsUpdate = true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -116,8 +116,10 @@ export class Button extends Behaviour implements IPointerEventHandler {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
onPointerClick(
|
|
119
|
+
onPointerClick(args: PointerEventData) {
|
|
120
120
|
if (!this.interactable) return;
|
|
121
|
+
// Button clicks should only run with left mouse button
|
|
122
|
+
if(args.pointerId !== 0) return;
|
|
121
123
|
if (debug) {
|
|
122
124
|
console.warn("Button Click", this.onClick);
|
|
123
125
|
showBalloonMessage("CLICKED button " + this.name + " at " + this.context.time.frameCount);
|
|
@@ -127,6 +127,7 @@ export class EventSystem extends Behaviour {
|
|
|
127
127
|
MeshUIHelper.resetLastSelected();
|
|
128
128
|
const opts = new PointerEventData(this.context.input);
|
|
129
129
|
opts.inputSource = ctrl;
|
|
130
|
+
opts.pointerId = 0;
|
|
130
131
|
opts.isDown = ctrl.selectionDown;
|
|
131
132
|
opts.isUp = ctrl.selectionUp;
|
|
132
133
|
opts.isPressed = ctrl.selectionPressed;
|
|
@@ -136,10 +137,11 @@ export class EventSystem extends Behaviour {
|
|
|
136
137
|
args.grab = null;
|
|
137
138
|
};
|
|
138
139
|
}
|
|
139
|
-
this._selectEndFn ??= (ctrl, args: { grab: THREE.Object3D }) => {
|
|
140
|
+
this._selectEndFn ??= (ctrl: WebXRController, args: { grab: THREE.Object3D }) => {
|
|
140
141
|
if (!args.grab) return;
|
|
141
142
|
const opts = new PointerEventData(this.context.input);
|
|
142
143
|
opts.inputSource = ctrl;
|
|
144
|
+
opts.pointerId = 0;
|
|
143
145
|
opts.isDown = ctrl.selectionDown;
|
|
144
146
|
opts.isUp = ctrl.selectionUp;
|
|
145
147
|
opts.isPressed = ctrl.selectionPressed;
|
|
@@ -3,7 +3,7 @@ import * as ThreeMeshUI from 'three-mesh-ui'
|
|
|
3
3
|
import { RGBAColor } from "../js-extensions/RGBAColor"
|
|
4
4
|
import { BaseUIComponent } from "./BaseUIComponent";
|
|
5
5
|
import { serializable } from '../../engine/engine_serialization_decorator';
|
|
6
|
-
import { Color,
|
|
6
|
+
import { Color, LinearSRGBColorSpace, SRGBColorSpace, Texture } from 'three';
|
|
7
7
|
import { RectTransform } from './RectTransform';
|
|
8
8
|
import { onChange, scheduleAction } from "./Utils"
|
|
9
9
|
import { GameObject } from '../Component';
|
|
@@ -191,12 +191,12 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
|
|
|
191
191
|
this.setOptions({ backgroundOpacity: 0 });
|
|
192
192
|
if (tex) {
|
|
193
193
|
// workaround for https://github.com/needle-tools/needle-engine-support/issues/109
|
|
194
|
-
if (tex.
|
|
194
|
+
if (tex.colorSpace === SRGBColorSpace) {
|
|
195
195
|
if (Graphic.textureCache.has(tex)) {
|
|
196
196
|
tex = Graphic.textureCache.get(tex)!;
|
|
197
197
|
} else {
|
|
198
198
|
const clone = tex.clone();
|
|
199
|
-
clone.
|
|
199
|
+
clone.colorSpace = LinearSRGBColorSpace;
|
|
200
200
|
Graphic.textureCache.set(tex, clone);
|
|
201
201
|
tex = clone;
|
|
202
202
|
}
|
|
@@ -370,7 +370,7 @@ export class WebXR extends Behaviour {
|
|
|
370
370
|
if (xrRig) {
|
|
371
371
|
// make it match unity forward
|
|
372
372
|
this.rig = xrRig.gameObject;
|
|
373
|
-
|
|
373
|
+
this.rig.rotateY(Math.PI);
|
|
374
374
|
// this.rig.position.copy(existing.worldPosition);
|
|
375
375
|
// this.rig.quaternion.premultiply(existing.worldQuaternion);
|
|
376
376
|
}
|