redhotmagma-visualization 1.47.10 → 1.48.0
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/DevApp.js +5 -0
- package/Three/Three3DScene.js +48 -8
- package/Utils/setLightShadow.js +6 -1
- package/package.json +2 -2
- package/src/DevApp.js +6 -0
- package/src/Three/Three3DScene.js +49 -15
- package/src/Utils/setLightShadow.js +2 -1
package/DevApp.js
CHANGED
|
@@ -802,6 +802,11 @@ var App = function App() {
|
|
|
802
802
|
}[mode] || mode;
|
|
803
803
|
var _visualization = (0, _visualizationAdapterCreator.createVisualizationAdapter)(adapterConfig, mappedMode);
|
|
804
804
|
setVisualization(_visualization);
|
|
805
|
+
_visualization.setOptions3D && _visualization.setOptions3D({
|
|
806
|
+
// uncomment lines to test different settings
|
|
807
|
+
//useDirectionalLight: true,
|
|
808
|
+
//useSoftShadow: true,
|
|
809
|
+
});
|
|
805
810
|
setEffect("");
|
|
806
811
|
setModel("");
|
|
807
812
|
}, [mode]);
|
package/Three/Three3DScene.js
CHANGED
|
@@ -295,6 +295,7 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
295
295
|
_defineProperty(_assertThisInitialized(_this), "groundObjectNames", [/ground/i]);
|
|
296
296
|
_defineProperty(_assertThisInitialized(_this), "config", {
|
|
297
297
|
useShadowGround: true,
|
|
298
|
+
shadowGroundShadowColor: 0x808080,
|
|
298
299
|
removeGroundForScreenshot: true,
|
|
299
300
|
useEnvironmentMap: true,
|
|
300
301
|
useDirectionalLight: false,
|
|
@@ -311,6 +312,14 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
311
312
|
blurRadius: 6,
|
|
312
313
|
shadowOpacity: 0.8
|
|
313
314
|
},
|
|
315
|
+
useSoftShadow: false,
|
|
316
|
+
softShadow: {
|
|
317
|
+
bias: -0.0001,
|
|
318
|
+
// for smaller models with closer shadow 0.001 can be more suitable
|
|
319
|
+
normalBias: 0.01,
|
|
320
|
+
shadowMapSize: 2048,
|
|
321
|
+
selfShadow: false
|
|
322
|
+
},
|
|
314
323
|
textureImageCacheSize: 20
|
|
315
324
|
});
|
|
316
325
|
_defineProperty(_assertThisInitialized(_this), "onLoadError", function (url) {
|
|
@@ -527,7 +536,7 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
527
536
|
});
|
|
528
537
|
} else {
|
|
529
538
|
shadowMaterial = new _three.ShadowMaterial({
|
|
530
|
-
color:
|
|
539
|
+
color: this.config.shadowGroundShadowColor
|
|
531
540
|
});
|
|
532
541
|
}
|
|
533
542
|
var mesh = new _three.Mesh(new _three.PlaneGeometry(1, 1), shadowMaterial);
|
|
@@ -542,12 +551,39 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
542
551
|
value: function setLightShadow(light) {
|
|
543
552
|
var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
|
|
544
553
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
554
|
+
if (this.config.useSoftShadow) {
|
|
555
|
+
(0, _setLightShadow2["default"])(light, d * 2, (0, _merge["default"])(this.calculateShadowProps(light), options));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}, {
|
|
559
|
+
key: "calculateShadowProps",
|
|
560
|
+
value: function calculateShadowProps(dirLight) {
|
|
561
|
+
var box = this.getSceneContainerBox();
|
|
562
|
+
var sphere = box.getBoundingSphere(new _three.Sphere());
|
|
563
|
+
var radius = sphere.radius;
|
|
564
|
+
var center = box.getCenter(new _three.Vector3());
|
|
565
|
+
var lightDistance = dirLight.getWorldPosition(new _three.Vector3()).sub(center).length();
|
|
566
|
+
var cameraProps = {
|
|
567
|
+
near: lightDistance - radius,
|
|
568
|
+
far: lightDistance * 2
|
|
569
|
+
};
|
|
570
|
+
return _objectSpread({
|
|
571
|
+
cameraProps: cameraProps
|
|
572
|
+
}, this.config.softShadow);
|
|
573
|
+
}
|
|
574
|
+
}, {
|
|
575
|
+
key: "fixSceneScaling",
|
|
576
|
+
value: function fixSceneScaling() {
|
|
577
|
+
this.sceneContainer.scale.set(1, 1, 1);
|
|
578
|
+
this.sceneContainer.updateWorldMatrix(true, true);
|
|
579
|
+
var box = this.getSceneContainerBox();
|
|
580
|
+
var size = box.getSize(new _three.Vector3()).length();
|
|
581
|
+
var sizeLog = Math.log10(size);
|
|
582
|
+
if (sizeLog >= 2) {
|
|
583
|
+
var scaling = 1 / Math.pow(10, Math.ceil(sizeLog));
|
|
584
|
+
this.sceneContainer.scale.set(scaling, scaling, scaling);
|
|
585
|
+
this.sceneContainer.updateWorldMatrix(true, true);
|
|
586
|
+
}
|
|
551
587
|
}
|
|
552
588
|
}, {
|
|
553
589
|
key: "createDirLight",
|
|
@@ -578,6 +614,9 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
578
614
|
scene.traverse(function (object) {
|
|
579
615
|
if (object.isMesh) {
|
|
580
616
|
object.castShadow = true;
|
|
617
|
+
if (_this3.config.softShadow.selfShadow) {
|
|
618
|
+
object.receiveShadow = true;
|
|
619
|
+
}
|
|
581
620
|
}
|
|
582
621
|
if (object.isLight && object.target && _this3.ground) {
|
|
583
622
|
object.target = _this3.ground;
|
|
@@ -1140,6 +1179,7 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
1140
1179
|
_context8.next = 24;
|
|
1141
1180
|
return this.initCustomizableMaterialsIfNeeded();
|
|
1142
1181
|
case 24:
|
|
1182
|
+
this.fixSceneScaling();
|
|
1143
1183
|
this.setupGround();
|
|
1144
1184
|
this.addLightsIfNeeded(sceneContainer);
|
|
1145
1185
|
this.fitSceneToCamera();
|
|
@@ -1154,7 +1194,7 @@ var Three3DScene = exports.Three3DScene = /*#__PURE__*/function (_Three3D) {
|
|
|
1154
1194
|
mixer.clipAction(animations[0]).play();
|
|
1155
1195
|
this.startAnimation("builtin");
|
|
1156
1196
|
}
|
|
1157
|
-
case
|
|
1197
|
+
case 31:
|
|
1158
1198
|
case "end":
|
|
1159
1199
|
return _context8.stop();
|
|
1160
1200
|
}
|
package/Utils/setLightShadow.js
CHANGED
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = setLightShadow;
|
|
7
|
+
var _excluded = ["shadowMapSize", "cameraProps"];
|
|
8
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
7
10
|
function setLightShadow(light) {
|
|
8
11
|
var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
|
|
9
12
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -11,7 +14,8 @@ function setLightShadow(light) {
|
|
|
11
14
|
var _options$shadowMapSiz = options.shadowMapSize,
|
|
12
15
|
shadowMapSize = _options$shadowMapSiz === void 0 ? 512 : _options$shadowMapSiz,
|
|
13
16
|
_options$cameraProps = options.cameraProps,
|
|
14
|
-
cameraProps = _options$cameraProps === void 0 ? {} : _options$cameraProps
|
|
17
|
+
cameraProps = _options$cameraProps === void 0 ? {} : _options$cameraProps,
|
|
18
|
+
shadowProps = _objectWithoutProperties(options, _excluded);
|
|
15
19
|
light.castShadow = true;
|
|
16
20
|
light.shadow.mapSize.width = shadowMapSize;
|
|
17
21
|
light.shadow.mapSize.height = shadowMapSize;
|
|
@@ -22,6 +26,7 @@ function setLightShadow(light) {
|
|
|
22
26
|
light.shadow.camera.near = 0.0001;
|
|
23
27
|
light.shadow.camera.far = 2 * d + 0.0001;
|
|
24
28
|
Object.assign(light.shadow.camera, cameraProps);
|
|
29
|
+
Object.assign(light.shadow, shadowProps);
|
|
25
30
|
light.shadow.camera.updateProjectionMatrix();
|
|
26
31
|
}
|
|
27
32
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redhotmagma-visualization",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/polyfill": "^7.12.1",
|
|
9
|
-
"@configuratorware/scripts": "1.
|
|
9
|
+
"@configuratorware/scripts": "1.48.0",
|
|
10
10
|
"@tweenjs/tween.js": "^17.6.0",
|
|
11
11
|
"console-polyfill": "^0.3.0",
|
|
12
12
|
"css-element-queries": "^1.2.3",
|
package/src/DevApp.js
CHANGED
|
@@ -666,6 +666,12 @@ const App = () => {
|
|
|
666
666
|
}[mode] || mode;
|
|
667
667
|
const _visualization = createVisualizationAdapter(adapterConfig, mappedMode);
|
|
668
668
|
setVisualization(_visualization);
|
|
669
|
+
_visualization.setOptions3D &&
|
|
670
|
+
_visualization.setOptions3D({
|
|
671
|
+
// uncomment lines to test different settings
|
|
672
|
+
//useDirectionalLight: true,
|
|
673
|
+
//useSoftShadow: true,
|
|
674
|
+
});
|
|
669
675
|
setEffect("");
|
|
670
676
|
setModel("");
|
|
671
677
|
}, [mode]);
|
|
@@ -274,6 +274,7 @@ export class Three3DScene extends Three3D {
|
|
|
274
274
|
|
|
275
275
|
config = {
|
|
276
276
|
useShadowGround: true,
|
|
277
|
+
shadowGroundShadowColor: 0x808080,
|
|
277
278
|
removeGroundForScreenshot: true,
|
|
278
279
|
useEnvironmentMap: true,
|
|
279
280
|
useDirectionalLight: false,
|
|
@@ -286,6 +287,13 @@ export class Three3DScene extends Three3D {
|
|
|
286
287
|
blurRadius: 6,
|
|
287
288
|
shadowOpacity: 0.8,
|
|
288
289
|
},
|
|
290
|
+
useSoftShadow: false,
|
|
291
|
+
softShadow: {
|
|
292
|
+
bias: -0.0001, // for smaller models with closer shadow 0.001 can be more suitable
|
|
293
|
+
normalBias: 0.01,
|
|
294
|
+
shadowMapSize: 2048,
|
|
295
|
+
selfShadow: false,
|
|
296
|
+
},
|
|
289
297
|
textureImageCacheSize: 20,
|
|
290
298
|
};
|
|
291
299
|
|
|
@@ -440,7 +448,7 @@ export class Three3DScene extends Three3D {
|
|
|
440
448
|
config: this.config.bakedShadow,
|
|
441
449
|
});
|
|
442
450
|
} else {
|
|
443
|
-
shadowMaterial = new ShadowMaterial({ color:
|
|
451
|
+
shadowMaterial = new ShadowMaterial({ color: this.config.shadowGroundShadowColor });
|
|
444
452
|
}
|
|
445
453
|
|
|
446
454
|
const mesh = new Mesh(new PlaneGeometry(1, 1), shadowMaterial);
|
|
@@ -452,20 +460,41 @@ export class Three3DScene extends Three3D {
|
|
|
452
460
|
}
|
|
453
461
|
|
|
454
462
|
setLightShadow(light, d = 50, options = {}) {
|
|
455
|
-
|
|
456
|
-
light,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
)
|
|
468
|
-
|
|
463
|
+
if (this.config.useSoftShadow) {
|
|
464
|
+
setLightShadow(light, d * 2, merge(this.calculateShadowProps(light), options));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
calculateShadowProps(dirLight) {
|
|
469
|
+
const box = this.getSceneContainerBox();
|
|
470
|
+
const sphere = box.getBoundingSphere(new Sphere());
|
|
471
|
+
const radius = sphere.radius;
|
|
472
|
+
const center = box.getCenter(new Vector3());
|
|
473
|
+
const lightDistance = dirLight
|
|
474
|
+
.getWorldPosition(new Vector3())
|
|
475
|
+
.sub(center)
|
|
476
|
+
.length();
|
|
477
|
+
const cameraProps = {
|
|
478
|
+
near: lightDistance - radius,
|
|
479
|
+
far: lightDistance * 2,
|
|
480
|
+
};
|
|
481
|
+
return {
|
|
482
|
+
cameraProps,
|
|
483
|
+
...this.config.softShadow,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
fixSceneScaling() {
|
|
488
|
+
this.sceneContainer.scale.set(1, 1, 1);
|
|
489
|
+
this.sceneContainer.updateWorldMatrix(true, true);
|
|
490
|
+
const box = this.getSceneContainerBox();
|
|
491
|
+
const size = box.getSize(new Vector3()).length();
|
|
492
|
+
const sizeLog = Math.log10(size);
|
|
493
|
+
if (sizeLog >= 2) {
|
|
494
|
+
const scaling = 1 / Math.pow(10, Math.ceil(sizeLog));
|
|
495
|
+
this.sceneContainer.scale.set(scaling, scaling, scaling);
|
|
496
|
+
this.sceneContainer.updateWorldMatrix(true, true);
|
|
497
|
+
}
|
|
469
498
|
}
|
|
470
499
|
|
|
471
500
|
createDirLight() {
|
|
@@ -496,6 +525,9 @@ export class Three3DScene extends Three3D {
|
|
|
496
525
|
scene.traverse(object => {
|
|
497
526
|
if (object.isMesh) {
|
|
498
527
|
object.castShadow = true;
|
|
528
|
+
if (this.config.softShadow.selfShadow) {
|
|
529
|
+
object.receiveShadow = true;
|
|
530
|
+
}
|
|
499
531
|
}
|
|
500
532
|
if (object.isLight && object.target && this.ground) {
|
|
501
533
|
object.target = this.ground;
|
|
@@ -918,6 +950,8 @@ export class Three3DScene extends Three3D {
|
|
|
918
950
|
|
|
919
951
|
await this.initCustomizableMaterialsIfNeeded();
|
|
920
952
|
|
|
953
|
+
this.fixSceneScaling();
|
|
954
|
+
|
|
921
955
|
this.setupGround();
|
|
922
956
|
|
|
923
957
|
this.addLightsIfNeeded(sceneContainer);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function setLightShadow(light, d = 50, options = {}) {
|
|
2
2
|
if (light.isDirectionalLight) {
|
|
3
|
-
const { shadowMapSize = 512, cameraProps = {} } = options;
|
|
3
|
+
const { shadowMapSize = 512, cameraProps = {}, ...shadowProps } = options;
|
|
4
4
|
|
|
5
5
|
light.castShadow = true;
|
|
6
6
|
light.shadow.mapSize.width = shadowMapSize;
|
|
@@ -12,6 +12,7 @@ export default function setLightShadow(light, d = 50, options = {}) {
|
|
|
12
12
|
light.shadow.camera.near = 0.0001;
|
|
13
13
|
light.shadow.camera.far = 2 * d + 0.0001;
|
|
14
14
|
Object.assign(light.shadow.camera, cameraProps);
|
|
15
|
+
Object.assign(light.shadow, shadowProps);
|
|
15
16
|
light.shadow.camera.updateProjectionMatrix();
|
|
16
17
|
}
|
|
17
18
|
}
|