@needle-tools/engine 3.7.6-beta → 3.8.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 +13 -0
- package/dist/needle-engine.js +472 -87008
- package/dist/needle-engine.light.js +472 -84467
- package/dist/needle-engine.light.min.js +1 -5805
- package/dist/needle-engine.light.umd.cjs +1 -5805
- package/dist/needle-engine.min.js +1 -5818
- package/dist/needle-engine.umd.cjs +1 -5818
- package/lib/engine/debug/debug.d.ts +1 -1
- package/lib/engine/engine_context.d.ts +3 -1
- package/lib/engine/engine_context.js +17 -12
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_lightdata.js +6 -7
- package/lib/engine/engine_lightdata.js.map +1 -1
- package/lib/engine/engine_networking_utils.d.ts +1 -1
- package/lib/engine/engine_networking_utils.js.map +1 -1
- package/lib/engine/engine_scenelighting.js +5 -5
- package/lib/engine/engine_scenelighting.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.js +3 -3
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.js +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +4 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine/extensions/extensions.js +17 -3
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine-components/Camera.js +3 -3
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/DragControls.js +4 -3
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/GroundProjection.js +1 -1
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/Light.js +58 -50
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +1 -1
- package/lib/engine-components/OrbitControls.js +4 -3
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +2 -1
- package/lib/engine-components/ParticleSystem.js +11 -1
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +3 -3
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.js +7 -7
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RendererLightmap.d.ts +2 -3
- package/lib/engine-components/RendererLightmap.js +16 -15
- package/lib/engine-components/RendererLightmap.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
- package/lib/engine-components/ui/BaseUIComponent.js +4 -0
- package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
- package/lib/engine-components/ui/Canvas.js +9 -1
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/PointerEvents.d.ts +1 -0
- package/lib/engine-components/ui/PointerEvents.js +5 -0
- package/lib/engine-components/ui/PointerEvents.js.map +1 -1
- package/lib/engine-components/utils/LookAt.js +7 -1
- package/lib/engine-components/utils/LookAt.js.map +1 -1
- package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
- package/lib/engine-components/webxr/WebARCameraBackground.js +2 -2
- package/lib/engine-components/webxr/WebARCameraBackground.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.js +6 -5
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components/webxr/WebXRPlaneTracking.d.ts +1 -1
- package/package.json +5 -5
- package/plugins/vite/vite-4.4-hack.js +25 -16
- package/src/engine/engine_context.ts +20 -13
- package/src/engine/engine_lightdata.ts +6 -8
- package/src/engine/engine_networking_utils.ts +1 -1
- package/src/engine/engine_scenelighting.ts +5 -5
- package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
- package/src/engine/extensions/NEEDLE_render_objects.ts +10 -8
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -1
- package/src/engine/extensions/extensions.ts +18 -3
- package/src/engine-components/Camera.ts +3 -3
- package/src/engine-components/DragControls.ts +7 -8
- package/src/engine-components/GroundProjection.ts +1 -1
- package/src/engine-components/Light.ts +62 -57
- package/src/engine-components/OrbitControls.ts +4 -3
- package/src/engine-components/ParticleSystem.ts +14 -0
- package/src/engine-components/ReflectionProbe.ts +3 -3
- package/src/engine-components/Renderer.ts +10 -10
- package/src/engine-components/RendererLightmap.ts +21 -20
- package/src/engine-components/ui/BaseUIComponent.ts +5 -0
- package/src/engine-components/ui/Canvas.ts +7 -1
- package/src/engine-components/ui/PointerEvents.ts +6 -0
- package/src/engine-components/utils/LookAt.ts +8 -1
- package/src/engine-components/webxr/WebARCameraBackground.ts +3 -3
- package/src/engine-components/webxr/WebXR.ts +6 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LightmapType } from "./extensions/NEEDLE_lightmaps";
|
|
2
|
-
import { Texture } from "three";
|
|
2
|
+
import { Texture, ShaderChunk, UniformsLib, Vector4 } from "three";
|
|
3
3
|
import { Context } from "./engine_setup";
|
|
4
|
-
import * as THREE from "three";
|
|
5
4
|
import { getParam } from "./engine_utils";
|
|
6
5
|
import { SourceIdentifier } from "./engine_types";
|
|
7
6
|
|
|
@@ -78,9 +77,8 @@ export class LightDataRegistry implements ILightDataRegistry {
|
|
|
78
77
|
// all the chunks we can patch
|
|
79
78
|
// console.log(THREE.ShaderChunk);
|
|
80
79
|
// Unity: ambientOrLightmapUV.xy = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; ambientOrLightmapUV.zw = 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
vec2 lUv = vUv2.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
|
|
80
|
+
ShaderChunk.lights_fragment_maps = ShaderChunk.lights_fragment_maps.replace("vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );", `
|
|
81
|
+
vec2 lUv = vLightMapUv.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
|
|
84
82
|
vec4 lightMapTexel = texture2D( lightMap, lUv);
|
|
85
83
|
// The range of RGBM lightmaps goes from 0 to 34.49 (5^2.2) in linear space, and from 0 to 5 in gamma space.
|
|
86
84
|
lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
|
|
@@ -88,7 +86,7 @@ THREE.ShaderChunk.lights_fragment_maps = THREE.ShaderChunk.lights_fragment_maps.
|
|
|
88
86
|
lightMapTexel = conv_sRGBToLinear(lightMapTexel);
|
|
89
87
|
`);
|
|
90
88
|
|
|
91
|
-
|
|
89
|
+
ShaderChunk.lightmap_pars_fragment = `
|
|
92
90
|
#ifdef USE_LIGHTMAP
|
|
93
91
|
uniform sampler2D lightMap;
|
|
94
92
|
uniform float lightMapIntensity;
|
|
@@ -105,7 +103,7 @@ THREE.ShaderChunk.lightmap_pars_fragment = `
|
|
|
105
103
|
// so they shouldn't receive light probe lighting.
|
|
106
104
|
// TODO: this gets difficult if there are additional real-time lightprobes added; we would need to exclude
|
|
107
105
|
// exactly those that were active when lighting was baked... that's complicated!
|
|
108
|
-
|
|
106
|
+
ShaderChunk.lights_fragment_begin = ShaderChunk.lights_fragment_begin.replace(
|
|
109
107
|
"irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );", `
|
|
110
108
|
#if defined(USE_LIGHTMAP)
|
|
111
109
|
irradiance += 0.;
|
|
@@ -113,4 +111,4 @@ irradiance += 0.;
|
|
|
113
111
|
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
114
112
|
#endif`);
|
|
115
113
|
|
|
116
|
-
|
|
114
|
+
UniformsLib.lightmap["lightmapScaleOffset"] = { value: new Vector4(1, 1, 0, 0) };
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
const localNetworkResults = new Map<string, boolean>();
|
|
8
8
|
|
|
9
9
|
export function isLocalNetwork(hostname = window.location.hostname) {
|
|
10
|
-
if(localNetworkResults.has(hostname)) return localNetworkResults.get(hostname)
|
|
10
|
+
if(localNetworkResults.has(hostname)) return localNetworkResults.get(hostname)!;
|
|
11
11
|
const isLocalNetwork = new RegExp("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|localhost", "gm").test(hostname);
|
|
12
12
|
localNetworkResults.set(hostname, isLocalNetwork);
|
|
13
13
|
if (isLocalNetwork === true) return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector4, EquirectangularReflectionMapping, sRGBEncoding, WebGLCubeRenderTarget, Texture, LightProbe, Color, SphericalHarmonics3 } from "three";
|
|
1
|
+
import { Vector4, EquirectangularReflectionMapping, sRGBEncoding, WebGLCubeRenderTarget, Texture, LightProbe, Color, SphericalHarmonics3, SRGBColorSpace } from "three";
|
|
2
2
|
import { LightProbeGenerator } from "three/examples/jsm/lights/LightProbeGenerator.js"
|
|
3
3
|
import { Context } from "./engine_setup";
|
|
4
4
|
import { SceneLightSettings } from "./extensions/NEEDLE_lighting_settings";
|
|
@@ -164,7 +164,7 @@ export class RendererData {
|
|
|
164
164
|
if (debug) console.log("Setting environment reflection", existing);
|
|
165
165
|
const scene = this.context.scene;
|
|
166
166
|
const tex = existing.Source;
|
|
167
|
-
tex.
|
|
167
|
+
tex.colorSpace = SRGBColorSpace;
|
|
168
168
|
tex.mapping = EquirectangularReflectionMapping;
|
|
169
169
|
scene.environment = tex;
|
|
170
170
|
return;
|
|
@@ -179,7 +179,7 @@ export class RendererData {
|
|
|
179
179
|
if (settings.ambientTrilight) {
|
|
180
180
|
const colors = settings.ambientTrilight;
|
|
181
181
|
const tex = createTrilightTexture(colors[0], colors[1], colors[2], 64, 64);
|
|
182
|
-
tex.
|
|
182
|
+
tex.colorSpace = SRGBColorSpace;
|
|
183
183
|
tex.mapping = EquirectangularReflectionMapping;
|
|
184
184
|
this.context.scene.environment = tex;
|
|
185
185
|
}
|
|
@@ -188,7 +188,7 @@ export class RendererData {
|
|
|
188
188
|
case AmbientMode.Flat:
|
|
189
189
|
if (settings.ambientLight) {
|
|
190
190
|
const tex = createFlatTexture(settings.ambientLight, 64);
|
|
191
|
-
tex.
|
|
191
|
+
tex.colorSpace = SRGBColorSpace;
|
|
192
192
|
tex.mapping = EquirectangularReflectionMapping;
|
|
193
193
|
this.context.scene.environment = tex;
|
|
194
194
|
}
|
|
@@ -259,7 +259,7 @@ export class LightData {
|
|
|
259
259
|
this._source = tex;
|
|
260
260
|
this._ambientScale = ambientScale;
|
|
261
261
|
tex.mapping = EquirectangularReflectionMapping;
|
|
262
|
-
tex.
|
|
262
|
+
tex.colorSpace = SRGBColorSpace;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
getSphericalHarmonicsArray(intensityFactor: number = 1): SphericalHarmonicsData | null {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILightDataRegistry } from "../engine_lightdata";
|
|
2
|
-
import { FloatType, HalfFloatType, LinearEncoding, sRGBEncoding, Texture } from "three";
|
|
2
|
+
import { FloatType, HalfFloatType, LinearEncoding, LinearSRGBColorSpace, SRGBColorSpace, sRGBEncoding, Texture } from "three";
|
|
3
3
|
import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
|
|
4
4
|
import { SourceIdentifier } from "../engine_types";
|
|
5
5
|
import { resolveReferences } from "./extension_utils";
|
|
@@ -70,9 +70,9 @@ export class NEEDLE_lightmaps implements GLTFLoaderPlugin {
|
|
|
70
70
|
else {
|
|
71
71
|
// TODO this is most likely wrong for floating point textures
|
|
72
72
|
if (entry.type !== LightmapType.Lightmap)
|
|
73
|
-
tex.
|
|
73
|
+
tex.colorSpace = SRGBColorSpace;
|
|
74
74
|
else
|
|
75
|
-
tex.
|
|
75
|
+
tex.colorSpace = LinearSRGBColorSpace;
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
// Dont flip skybox textures anymore - previously we exported them flipped when baking in Unity but now we allow to pass through export without re-baking exisitng skybox textures if they use default values. So we expect textures to be NOT flipped anymore
|
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
IncrementWrapStencilOp,
|
|
23
23
|
DecrementWrapStencilOp,
|
|
24
24
|
InvertStencilOp,
|
|
25
|
+
StencilFunc,
|
|
26
|
+
StencilOp as ThreeStencilOp,
|
|
25
27
|
} from "three";
|
|
26
28
|
import { getParam, isDebugMode } from "../engine_utils";
|
|
27
29
|
import { showBalloonWarning } from "../debug";
|
|
@@ -81,10 +83,10 @@ export class NEEDLE_render_objects implements GLTFLoaderPlugin {
|
|
|
81
83
|
mat.stencilWriteMask = 255;
|
|
82
84
|
mat.stencilFuncMask = 255;
|
|
83
85
|
mat.stencilRef = stencil.value;
|
|
84
|
-
mat.stencilFunc = stencil.compareFunc;
|
|
85
|
-
mat.stencilZPass = stencil.passOp;
|
|
86
|
-
mat.stencilFail = stencil.failOp;
|
|
87
|
-
mat.stencilZFail = stencil.zFailOp;
|
|
86
|
+
mat.stencilFunc = stencil.compareFunc as StencilFunc;
|
|
87
|
+
mat.stencilZPass = stencil.passOp as ThreeStencilOp;
|
|
88
|
+
mat.stencilFail = stencil.failOp as ThreeStencilOp;
|
|
89
|
+
mat.stencilZFail = stencil.zFailOp as ThreeStencilOp;
|
|
88
90
|
obj.sharedMaterials[i] = mat;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -116,7 +118,7 @@ export class NEEDLE_render_objects implements GLTFLoaderPlugin {
|
|
|
116
118
|
if (stencils && Array.isArray(stencils)) {
|
|
117
119
|
for (const stencil of stencils) {
|
|
118
120
|
const obj: StencilSettingsModel = { ...stencil };
|
|
119
|
-
obj.compareFunc = ToThreeCompareFunction(obj.compareFunc);
|
|
121
|
+
obj.compareFunc = ToThreeCompareFunction(obj.compareFunc as number);
|
|
120
122
|
obj.passOp = ToThreeStencilOp(obj.passOp);
|
|
121
123
|
obj.failOp = ToThreeStencilOp(obj.failOp);
|
|
122
124
|
obj.zFailOp = ToThreeStencilOp(obj.zFailOp);
|
|
@@ -161,7 +163,7 @@ enum CompareFunction {
|
|
|
161
163
|
Always,
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
function ToThreeStencilOp(op: StencilOp):
|
|
166
|
+
function ToThreeStencilOp(op: StencilOp): ThreeStencilOp {
|
|
165
167
|
switch (op) {
|
|
166
168
|
case StencilOp.Keep:
|
|
167
169
|
return KeepStencilOp;
|
|
@@ -183,7 +185,7 @@ function ToThreeStencilOp(op: StencilOp): number {
|
|
|
183
185
|
return 0;
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
function ToThreeCompareFunction(func: CompareFunction):
|
|
188
|
+
function ToThreeCompareFunction(func: CompareFunction): StencilFunc {
|
|
187
189
|
switch (func) {
|
|
188
190
|
case CompareFunction.Never:
|
|
189
191
|
return NeverStencilFunc;
|
|
@@ -202,7 +204,7 @@ function ToThreeCompareFunction(func: CompareFunction): number {
|
|
|
202
204
|
case CompareFunction.Always:
|
|
203
205
|
return AlwaysStencilFunc;
|
|
204
206
|
}
|
|
205
|
-
return
|
|
207
|
+
return NeverStencilFunc;
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
|
|
2
2
|
import { FindShaderTechniques, whiteDefaultTexture, ToUnityMatrixArray, SetUnitySphericalHarmonics } from '../engine_shaders';
|
|
3
|
-
import { AlwaysDepth, BackSide, Camera, DoubleSide, EqualDepth, FrontSide, GreaterDepth, GreaterEqualDepth, IUniform, LessDepth, LessEqualDepth, LinearEncoding, Material, Matrix4, NotEqualDepth, Object3D, RawShaderMaterial, Vector3, Vector4 } from 'three';
|
|
3
|
+
import { AlwaysDepth, BackSide, Camera, DoubleSide, EqualDepth, FrontSide, GLSL3, GreaterDepth, GreaterEqualDepth, IUniform, LessDepth, LessEqualDepth, LinearEncoding, Material, Matrix4, NotEqualDepth, Object3D, RawShaderMaterial, Vector3, Vector4 } from 'three';
|
|
4
4
|
import { Context } from '../engine_setup';
|
|
5
5
|
import { getParam } from "../engine_utils";
|
|
6
6
|
import * as SHADERDATA from "../shaders/shaderData"
|
|
@@ -455,6 +455,10 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
455
455
|
// "USE_SHADOWMAP" : true
|
|
456
456
|
// },
|
|
457
457
|
});
|
|
458
|
+
material.glslVersion = GLSL3;
|
|
459
|
+
material.vertexShader = material.vertexShader.replace("#version 300 es", "");
|
|
460
|
+
material.fragmentShader = material.fragmentShader.replace("#version 300 es", "");
|
|
461
|
+
|
|
458
462
|
|
|
459
463
|
const culling = uniforms["_Cull"]?.value;
|
|
460
464
|
switch (culling) {
|
|
@@ -16,6 +16,16 @@ import { NEEDLE_progressive } from "./NEEDLE_progressive";
|
|
|
16
16
|
import { InternalUsageTrackerPlugin } from "./usage_tracker";
|
|
17
17
|
import { isUsageTrackingEnabled } from "../engine_assetdatabase";
|
|
18
18
|
import { GLTFLoaderPlugin } from "three/examples/jsm/loaders/GLTFLoader";
|
|
19
|
+
// import { GLTFAnimationPointerExtension } from "three/examples/jsm/loaders/GLTFLoaderAnimationPointer";
|
|
20
|
+
|
|
21
|
+
// lazily import the GLTFAnimationPointerExtension in case it doesnt exist (e.g. using vanilla three)
|
|
22
|
+
let GLTFAnimationPointerExtension : any;
|
|
23
|
+
import("three/examples/jsm/loaders/GLTFLoaderAnimationPointer").then(mod => {
|
|
24
|
+
GLTFAnimationPointerExtension = mod.GLTFAnimationPointerExtension;
|
|
25
|
+
return GLTFAnimationPointerExtension;
|
|
26
|
+
}).catch(e => {
|
|
27
|
+
console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support", e);
|
|
28
|
+
});
|
|
19
29
|
|
|
20
30
|
const _addedCustomExtension = new Array<ConstructorConcrete<GLTFLoaderPlugin>>();
|
|
21
31
|
|
|
@@ -70,8 +80,13 @@ export function registerExtensions(loader: GLTFLoader, context: Context, sourceI
|
|
|
70
80
|
for (const ext of _addedCustomExtension)
|
|
71
81
|
loader.register(p => new ext(p));
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
loader.register(p => {
|
|
84
|
+
if (GLTFAnimationPointerExtension) {
|
|
85
|
+
const ext = new GLTFAnimationPointerExtension(p);
|
|
86
|
+
const setPointerResolverFunction = ext.setAnimationPointerResolver;
|
|
87
|
+
setPointerResolverFunction.bind(ext)(new PointerResolver());
|
|
88
|
+
return ext;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
76
91
|
|
|
77
92
|
}
|
|
@@ -8,7 +8,7 @@ import { showBalloonMessage } from "../engine/debug/debug";
|
|
|
8
8
|
import { getWorldPosition, Graphics } from "../engine/engine_three_utils";
|
|
9
9
|
import { Gizmos } from "../engine/engine_gizmos";
|
|
10
10
|
|
|
11
|
-
import { EquirectangularReflectionMapping, OrthographicCamera, PerspectiveCamera, Ray, sRGBEncoding, Vector3 } from "three";
|
|
11
|
+
import { EquirectangularReflectionMapping, OrthographicCamera, PerspectiveCamera, Ray, SRGBColorSpace, sRGBEncoding, Vector3 } from "three";
|
|
12
12
|
import { OrbitControls } from "./OrbitControls";
|
|
13
13
|
import { RenderTexture } from "../engine/engine_texture";
|
|
14
14
|
|
|
@@ -261,7 +261,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
261
261
|
else
|
|
262
262
|
cam = this.gameObject.children[0] as THREE.PerspectiveCamera | THREE.OrthographicCamera | null;
|
|
263
263
|
if (cam && cam.isCamera) {
|
|
264
|
-
if (cam
|
|
264
|
+
if (cam instanceof PerspectiveCamera) {
|
|
265
265
|
if (this._fov)
|
|
266
266
|
cam.fov = this._fov;
|
|
267
267
|
cam.near = this._nearClipPlane;
|
|
@@ -391,7 +391,7 @@ class CameraSkybox {
|
|
|
391
391
|
else if (this.context.scene.background !== this._skybox) {
|
|
392
392
|
if (debug)
|
|
393
393
|
console.log("Set skybox", this._camera, this._skybox);
|
|
394
|
-
this._skybox.
|
|
394
|
+
this._skybox.colorSpace = SRGBColorSpace;
|
|
395
395
|
this._skybox.mapping = EquirectangularReflectionMapping;
|
|
396
396
|
this.context.scene.background = this._skybox;
|
|
397
397
|
}
|
|
@@ -108,8 +108,9 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
108
108
|
DragControls._active += 1;
|
|
109
109
|
this._dragDelta.set(0, 0);
|
|
110
110
|
this._didDrag = false;
|
|
111
|
-
this
|
|
112
|
-
args.
|
|
111
|
+
// Clone to not modify the original event (and this event is used in the actual onDragStart method)
|
|
112
|
+
this._waitingForDragStart = args.clone();
|
|
113
|
+
args.stopPropagation();
|
|
113
114
|
// disabling pointer controls here already, otherwise we get a few frames of movement event in orbit controls and this will rotate the camera sligthly AFTER drag controls dragging ends.
|
|
114
115
|
if (this.orbit) this.orbit.enabled = false;
|
|
115
116
|
}
|
|
@@ -117,11 +118,11 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
117
118
|
onPointerUp(args: PointerEventData) {
|
|
118
119
|
this._waitingForDragStart = null;
|
|
119
120
|
if (!this.allowEdit(this.gameObject)) return;
|
|
120
|
-
if(DragControls._active > 0)
|
|
121
|
+
if (DragControls._active > 0)
|
|
121
122
|
DragControls._active -= 1;
|
|
122
123
|
if (WebXR.IsInWebXR) return;
|
|
123
124
|
this.onDragEnd(args);
|
|
124
|
-
args.
|
|
125
|
+
args.stopPropagation();
|
|
125
126
|
if (this.orbit) this.orbit.enabled = true;
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -131,7 +132,6 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
131
132
|
|
|
132
133
|
// drag start only after having dragged for some pixels
|
|
133
134
|
if (this._waitingForDragStart) {
|
|
134
|
-
|
|
135
135
|
if (!this._didDrag) {
|
|
136
136
|
// this is so we can e.g. process clicks without having a drag change the position
|
|
137
137
|
// e.g. a click to rotate the object
|
|
@@ -142,7 +142,6 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
142
142
|
this._didDrag = true;
|
|
143
143
|
else return;
|
|
144
144
|
}
|
|
145
|
-
|
|
146
145
|
const args = this._waitingForDragStart;
|
|
147
146
|
this._waitingForDragStart = null;
|
|
148
147
|
this.onDragStart(args);
|
|
@@ -247,7 +246,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
247
246
|
if (!this || !this._isDragging) return;
|
|
248
247
|
this._isDragging = false;
|
|
249
248
|
if (!this._dragHelper) return;
|
|
250
|
-
for(const rb of this._draggingRigidbodies){
|
|
249
|
+
for (const rb of this._draggingRigidbodies) {
|
|
251
250
|
rb.setVelocity(rb.smoothedVelocity);
|
|
252
251
|
}
|
|
253
252
|
this._draggingRigidbodies.length = 0;
|
|
@@ -336,7 +335,7 @@ class DragHelper {
|
|
|
336
335
|
for (const rb of this._rbs) {
|
|
337
336
|
rb.wakeUp();
|
|
338
337
|
// if (!rb.smoothedVelocity) continue;
|
|
339
|
-
rb.setVelocity(0,0,0);
|
|
338
|
+
rb.setVelocity(0, 0, 0);
|
|
340
339
|
}
|
|
341
340
|
}
|
|
342
341
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behaviour, GameObject } from "./Component";
|
|
2
|
-
import {
|
|
2
|
+
import { GroundProjectedSkybox as GroundProjection } from 'three/examples/jsm/objects/GroundProjectedSkybox.js';
|
|
3
3
|
import { serializable } from "../engine/engine_serialization_decorator";
|
|
4
4
|
import { Watch as Watch } from "../engine/engine_utils";
|
|
5
5
|
import { Texture } from "three";
|
|
@@ -173,6 +173,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
173
173
|
}
|
|
174
174
|
this.light.intensity = val * factor;
|
|
175
175
|
}
|
|
176
|
+
if (debug) console.log("Set light intensity to " + this._intensity, val, this)
|
|
176
177
|
}
|
|
177
178
|
get intensity(): number { return this._intensity; }
|
|
178
179
|
private _intensity: number = -1;
|
|
@@ -180,7 +181,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
180
181
|
@serializable()
|
|
181
182
|
get shadowDistance(): number {
|
|
182
183
|
const light = this.light;
|
|
183
|
-
if (light) {
|
|
184
|
+
if (light?.shadow) {
|
|
184
185
|
const cam = light.shadow.camera as OrthographicCamera;
|
|
185
186
|
return cam.far;
|
|
186
187
|
}
|
|
@@ -189,7 +190,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
189
190
|
set shadowDistance(val: number) {
|
|
190
191
|
this._shadowDistance = val;
|
|
191
192
|
const light = this.light;
|
|
192
|
-
if (light) {
|
|
193
|
+
if (light?.shadow) {
|
|
193
194
|
const cam = light.shadow.camera as OrthographicCamera;
|
|
194
195
|
cam.far = val;
|
|
195
196
|
cam.updateProjectionMatrix();
|
|
@@ -203,7 +204,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
203
204
|
@serializable()
|
|
204
205
|
get shadowResolution(): number {
|
|
205
206
|
const light = this.light;
|
|
206
|
-
if (light) {
|
|
207
|
+
if (light?.shadow) {
|
|
207
208
|
return light.shadow.mapSize.x;
|
|
208
209
|
}
|
|
209
210
|
return -1;
|
|
@@ -212,7 +213,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
212
213
|
if (val === this._shadowResolution) return;
|
|
213
214
|
this._shadowResolution = val;
|
|
214
215
|
const light = this.light;
|
|
215
|
-
if (light) {
|
|
216
|
+
if (light?.shadow) {
|
|
216
217
|
light.shadow.mapSize.set(val, val);
|
|
217
218
|
light.shadow.needsUpdate = true;
|
|
218
219
|
}
|
|
@@ -256,12 +257,13 @@ export class Light extends Behaviour implements ILight {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
onEnable(): void {
|
|
259
|
-
if(debug) console.log("ENABLE LIGHT", this.name);
|
|
260
|
+
if (debug) console.log("ENABLE LIGHT", this.name);
|
|
260
261
|
this.createLight();
|
|
261
262
|
if (this.isBaked) return;
|
|
262
263
|
else if (this.light) {
|
|
263
264
|
this.light.visible = true;
|
|
264
265
|
this.light.intensity = this._intensity;
|
|
266
|
+
if (debug) console.log("Set light intensity to " + this.light.intensity, this.name)
|
|
265
267
|
if (this.selfIsLight) {
|
|
266
268
|
// nothing to do
|
|
267
269
|
}
|
|
@@ -275,7 +277,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
onDisable() {
|
|
278
|
-
if(debug) console.log("DISABLE LIGHT", this.name);
|
|
280
|
+
if (debug) console.log("DISABLE LIGHT", this.name);
|
|
279
281
|
if (this.light) {
|
|
280
282
|
if (this.selfIsLight)
|
|
281
283
|
this.light.intensity = 0;
|
|
@@ -376,61 +378,63 @@ export class Light extends Behaviour implements ILight {
|
|
|
376
378
|
}
|
|
377
379
|
else this.light.castShadow = false;
|
|
378
380
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
this.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
381
|
+
if (this.light.shadow) {
|
|
382
|
+
// shadow intensity is currently not a thing: https://github.com/mrdoob/three.js/pull/14087
|
|
383
|
+
if (this._shadowResolution !== undefined && this._shadowResolution > 4) {
|
|
384
|
+
this.light.shadow.mapSize.width = this._shadowResolution;
|
|
385
|
+
this.light.shadow.mapSize.height = this._shadowResolution;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
this.light.shadow.mapSize.width = 2048;
|
|
389
|
+
this.light.shadow.mapSize.height = 2048;
|
|
390
|
+
}
|
|
391
|
+
// this.light.shadow.needsUpdate = true;
|
|
392
|
+
// console.log(this.light.shadow.mapSize);
|
|
393
|
+
// return;
|
|
394
|
+
|
|
395
|
+
if (debug)
|
|
396
|
+
console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
|
|
397
|
+
|
|
398
|
+
this.light.shadow.bias = this.shadowBias;
|
|
399
|
+
this.light.shadow.normalBias = this.shadowNormalBias;
|
|
400
|
+
|
|
401
|
+
this.updateShadowSoftHard();
|
|
402
|
+
|
|
403
|
+
const cam = this.light.shadow.camera as THREE.OrthographicCamera;
|
|
404
|
+
cam.near = this.shadowNearPlane;
|
|
405
|
+
// use shadow distance that was set explictly (if any)
|
|
406
|
+
if (this._shadowDistance !== undefined && typeof this._shadowDistance === "number")
|
|
407
|
+
cam.far = this._shadowDistance;
|
|
408
|
+
else // otherwise fallback to object scale and max distance
|
|
409
|
+
cam.far = shadowMaxDistance * Math.abs(this.gameObject.scale.z);
|
|
410
|
+
|
|
411
|
+
// width and height
|
|
412
|
+
this.gameObject.scale.set(1, 1, 1);
|
|
413
|
+
if (this.shadowWidth !== undefined) {
|
|
414
|
+
cam.left = -this.shadowWidth / 2;
|
|
415
|
+
cam.right = this.shadowWidth / 2;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
const sx = this.gameObject.scale.x;
|
|
419
|
+
cam.left *= sx;
|
|
420
|
+
cam.right *= sx;
|
|
421
|
+
}
|
|
422
|
+
if (this.shadowHeight !== undefined) {
|
|
423
|
+
cam.top = this.shadowHeight / 2;
|
|
424
|
+
cam.bottom = -this.shadowHeight / 2;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
const sy = this.gameObject.scale.y;
|
|
428
|
+
cam.top *= sy;
|
|
429
|
+
cam.bottom *= sy;
|
|
430
|
+
}
|
|
431
|
+
this.light.shadow.needsUpdate = true;
|
|
399
432
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
// use shadow distance that was set explictly (if any)
|
|
403
|
-
if (this._shadowDistance !== undefined && typeof this._shadowDistance === "number")
|
|
404
|
-
cam.far = this._shadowDistance;
|
|
405
|
-
else // otherwise fallback to object scale and max distance
|
|
406
|
-
cam.far = shadowMaxDistance * Math.abs(this.gameObject.scale.z);
|
|
407
|
-
|
|
408
|
-
// width and height
|
|
409
|
-
this.gameObject.scale.set(1, 1, 1);
|
|
410
|
-
if (this.shadowWidth !== undefined) {
|
|
411
|
-
cam.left = -this.shadowWidth / 2;
|
|
412
|
-
cam.right = this.shadowWidth / 2;
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
const sx = this.gameObject.scale.x;
|
|
416
|
-
cam.left *= sx;
|
|
417
|
-
cam.right *= sx;
|
|
418
|
-
}
|
|
419
|
-
if (this.shadowHeight !== undefined) {
|
|
420
|
-
cam.top = this.shadowHeight / 2;
|
|
421
|
-
cam.bottom = -this.shadowHeight / 2;
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
const sy = this.gameObject.scale.y;
|
|
425
|
-
cam.top *= sy;
|
|
426
|
-
cam.bottom *= sy;
|
|
433
|
+
if (debug)
|
|
434
|
+
this.context.scene.add(new THREE.CameraHelper(cam));
|
|
427
435
|
}
|
|
428
436
|
|
|
429
437
|
|
|
430
|
-
this.light.shadow.needsUpdate = true;
|
|
431
|
-
if (debug)
|
|
432
|
-
this.context.scene.add(new THREE.CameraHelper(cam));
|
|
433
|
-
|
|
434
438
|
|
|
435
439
|
if (this.isBaked) {
|
|
436
440
|
this.light.removeFromParent();
|
|
@@ -457,6 +461,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
457
461
|
|
|
458
462
|
private updateShadowSoftHard() {
|
|
459
463
|
if (!this.light) return;
|
|
464
|
+
if (!this.light.shadow) return;
|
|
460
465
|
if (this.shadows === LightShadows.Soft) {
|
|
461
466
|
// const radius = this.light.shadow.mapSize.width / 1024 * 5;
|
|
462
467
|
// const samples = Mathf.clamp(Math.round(radius), 2, 10);
|
|
@@ -272,10 +272,10 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
272
272
|
if (!freeCam && this.lookAtConstraint?.locked) this.setFromTargetPosition(0, this.lookAtConstraint01);
|
|
273
273
|
|
|
274
274
|
|
|
275
|
-
if (this._controls
|
|
275
|
+
if (this._controls) {
|
|
276
276
|
if (this.debugLog)
|
|
277
277
|
this._controls.domElement = this.context.renderer.domElement;
|
|
278
|
-
this._controls.enabled = !this._shouldDisable && this._camera === this.context.mainCameraComponent;
|
|
278
|
+
this._controls.enabled = !this._shouldDisable && this._camera === this.context.mainCameraComponent && !this.context.isInXR;
|
|
279
279
|
this._controls.enableDamping = this.enableDamping;
|
|
280
280
|
this._controls.keys = this.enableKeys ? defaultKeys : disabledKeys;
|
|
281
281
|
this._controls.autoRotate = this.autoRotate;
|
|
@@ -283,7 +283,8 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
283
283
|
this._controls.enableZoom = this.enableZoom;
|
|
284
284
|
this._controls.dampingFactor = this.dampingFactor;
|
|
285
285
|
this._controls.enablePan = this.enablePan;
|
|
286
|
-
this.
|
|
286
|
+
if (!this.context.isInXR)
|
|
287
|
+
this._controls.update();
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
|
|
@@ -69,7 +69,21 @@ export class ParticleSystemRenderer extends Behaviour {
|
|
|
69
69
|
return res;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
private static _havePatchedQuarkShaders = false;
|
|
73
|
+
|
|
72
74
|
getMaterial(trailEnabled: boolean = false) {
|
|
75
|
+
|
|
76
|
+
if (!ParticleSystemRenderer._havePatchedQuarkShaders) {
|
|
77
|
+
ParticleSystemRenderer._havePatchedQuarkShaders = true;
|
|
78
|
+
|
|
79
|
+
// HACK patch three.quarks fo three152+, see https://github.com/Alchemist0823/three.quarks/issues/56#issuecomment-1560825038
|
|
80
|
+
const _rebuild = TrailBatch.prototype.rebuildMaterial;
|
|
81
|
+
TrailBatch.prototype.rebuildMaterial = function () {
|
|
82
|
+
_rebuild.call(this);
|
|
83
|
+
this.material.defines.MAP_UV = "uv";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
73
87
|
const material = (trailEnabled === true && this.trailMaterial) ? this.trailMaterial : this.particleMaterial;
|
|
74
88
|
|
|
75
89
|
// progressive load on start
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behaviour } from "./Component";
|
|
2
|
-
import { Box3, Color, EquirectangularReflectionMapping, LinearEncoding, LineBasicMaterial, Material, MeshStandardMaterial, Object3D, SrcAlphaFactor, sRGBEncoding, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderTarget } from "three";
|
|
2
|
+
import { Box3, Color, EquirectangularReflectionMapping, LinearEncoding, LineBasicMaterial, Material, MeshStandardMaterial, Object3D, SrcAlphaFactor, SRGBColorSpace, sRGBEncoding, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderTarget } from "three";
|
|
3
3
|
import { serializable } from "../engine/engine_serialization";
|
|
4
4
|
import { Context } from "../engine/engine_setup";
|
|
5
5
|
import { getWorldPosition, getWorldScale } from "../engine/engine_three_utils";
|
|
@@ -54,7 +54,7 @@ export class ReflectionProbe extends Behaviour {
|
|
|
54
54
|
this._texture = tex;
|
|
55
55
|
if (tex) {
|
|
56
56
|
tex.mapping = EquirectangularReflectionMapping;
|
|
57
|
-
tex.
|
|
57
|
+
tex.colorSpace = SRGBColorSpace;
|
|
58
58
|
tex.needsUpdate = true;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -89,7 +89,7 @@ export class ReflectionProbe extends Behaviour {
|
|
|
89
89
|
|
|
90
90
|
if (this.texture) {
|
|
91
91
|
this.texture.mapping = EquirectangularReflectionMapping;
|
|
92
|
-
this.texture.
|
|
92
|
+
this.texture.colorSpace = SRGBColorSpace;
|
|
93
93
|
this.texture.needsUpdate = true;
|
|
94
94
|
}
|
|
95
95
|
}
|