@archvisioninc/canvas 3.3.6 → 3.3.8
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/.claude/settings.local.json +8 -0
- package/README_DEV.md +4 -1
- package/package.json +1 -1
- package/src/package/helpers/canvasUpdateHelpers.js +145 -0
- package/src/package/helpers/initHelpers.js +10 -0
- package/src/package/helpers/utilityHelpers.js +17 -0
- package/dist/Canvas.js +0 -67
- package/dist/actions/index.js +0 -1
- package/dist/actions/shortcutActions.js +0 -313
- package/dist/constants/constants.js +0 -80
- package/dist/constants/index.js +0 -1
- package/dist/enums/aspectRatios.js +0 -17
- package/dist/enums/dimensions.js +0 -20
- package/dist/enums/downscaling.js +0 -16
- package/dist/enums/exclusions.js +0 -4
- package/dist/enums/formats.js +0 -1
- package/dist/enums/index.js +0 -8
- package/dist/enums/orthoOptions.js +0 -28
- package/dist/enums/scaleUnits.js +0 -25
- package/dist/enums/shortcuts.js +0 -89
- package/dist/helpers/cameraHelpers.js +0 -86
- package/dist/helpers/canvasAddHelpers.js +0 -161
- package/dist/helpers/canvasCommunicationHelpers.js +0 -52
- package/dist/helpers/canvasRemoveHelpers.js +0 -230
- package/dist/helpers/canvasUpdateHelpers.js +0 -1247
- package/dist/helpers/gizmoHelpers.js +0 -156
- package/dist/helpers/guiHelpers.js +0 -46
- package/dist/helpers/index.js +0 -16
- package/dist/helpers/initHelpers.js +0 -507
- package/dist/helpers/lightHelpers.js +0 -17
- package/dist/helpers/loadHelpers.js +0 -269
- package/dist/helpers/materialHelpers.js +0 -34
- package/dist/helpers/meshHelpers.js +0 -169
- package/dist/helpers/rayHelpers.js +0 -11
- package/dist/helpers/shortcutHelpers.js +0 -35
- package/dist/helpers/utilityHelpers.js +0 -697
- package/dist/helpers/viewportHelpers.js +0 -364
- package/dist/styles.js +0 -25
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export const TEXTURE_SIZE_THRESHOLD = 4096;
|
|
2
|
-
export const MATERIAL_COUNT_THRESHOLD = 50;
|
|
3
|
-
export const MESH_COUNT_THRESHOLD = 500;
|
|
4
|
-
export const INSPECTOR = {
|
|
5
|
-
root: '__root__'
|
|
6
|
-
};
|
|
7
|
-
export const LISTENERS = {
|
|
8
|
-
resize: 'resize',
|
|
9
|
-
keyup: 'keyup'
|
|
10
|
-
};
|
|
11
|
-
export const LIGHTS = {
|
|
12
|
-
SpotLight: 'SpotLight',
|
|
13
|
-
ShadowGenerator: 'ShadowGenerator',
|
|
14
|
-
PointLight: 'PointLight',
|
|
15
|
-
DirectionalLight: 'DirectionalLight',
|
|
16
|
-
HemisphericLight: 'HemisphericLight',
|
|
17
|
-
GroundLight: 'GroundLight'
|
|
18
|
-
};
|
|
19
|
-
export const CAMERAS = {
|
|
20
|
-
FreeCamera: 'FreeCamera',
|
|
21
|
-
FlyCamera: 'FlyCamera',
|
|
22
|
-
FollowCamera: 'FollowCamera',
|
|
23
|
-
GamepadCamera: 'GamepadCamera',
|
|
24
|
-
TouchCamera: 'TouchCamera',
|
|
25
|
-
UniversalCamera: 'UniversalCamera',
|
|
26
|
-
ArcRotateCamera: 'ArcRotateCamera'
|
|
27
|
-
};
|
|
28
|
-
export const VIEWPORT = {
|
|
29
|
-
shadowMapSize: 4096
|
|
30
|
-
};
|
|
31
|
-
export const GIZMOS = {
|
|
32
|
-
RotationGizmo: 'RotationGizmo',
|
|
33
|
-
PositionGizmo: 'PositionGizmo',
|
|
34
|
-
ScaleGizmo: 'ScaleGizmo',
|
|
35
|
-
BoundingBoxGizmo: 'BoundingBoxGizmo'
|
|
36
|
-
};
|
|
37
|
-
export const ORTHO = {
|
|
38
|
-
left: 'orthoLeft',
|
|
39
|
-
right: 'orthoRight',
|
|
40
|
-
top: 'orthoTop',
|
|
41
|
-
bottom: 'orthoBottom'
|
|
42
|
-
};
|
|
43
|
-
export const GUI = {
|
|
44
|
-
dragSelectBox: 'dragSelectBox',
|
|
45
|
-
innerSafeFrame: 'safeFrame_inner',
|
|
46
|
-
outerSafeFrame: 'safeFrame_outer'
|
|
47
|
-
};
|
|
48
|
-
export const MESH_PARAMS = {
|
|
49
|
-
center: 'center',
|
|
50
|
-
rotation: 'rotation',
|
|
51
|
-
scaling: 'scaling',
|
|
52
|
-
radius: 'radius'
|
|
53
|
-
};
|
|
54
|
-
export const MESSAGE_TYPES = {
|
|
55
|
-
error: 'error',
|
|
56
|
-
warning: 'warning',
|
|
57
|
-
info: 'info',
|
|
58
|
-
success: 'success',
|
|
59
|
-
loading: 'loading'
|
|
60
|
-
};
|
|
61
|
-
export const UPDATABLE_ITEMS = {
|
|
62
|
-
material: 'material',
|
|
63
|
-
mesh: 'mesh',
|
|
64
|
-
camera: 'camera',
|
|
65
|
-
environment: 'environment',
|
|
66
|
-
texture: 'texture',
|
|
67
|
-
viewport: 'viewport',
|
|
68
|
-
publish: 'publish',
|
|
69
|
-
lighting: 'lighting'
|
|
70
|
-
};
|
|
71
|
-
export const TRANSPARENCY_MODES = {
|
|
72
|
-
simple: 'simple',
|
|
73
|
-
complex: 'complex',
|
|
74
|
-
stencil: 'stencil'
|
|
75
|
-
};
|
|
76
|
-
export const AXIS_COLORS = {
|
|
77
|
-
xAxis: '#EA4231',
|
|
78
|
-
yAxis: '#249C4A',
|
|
79
|
-
zAxis: '#0089EA'
|
|
80
|
-
};
|
package/dist/constants/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './constants';
|
package/dist/enums/dimensions.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AXIS_COLORS } from '../constants';
|
|
2
|
-
export const dimensions = [{
|
|
3
|
-
name: 'length',
|
|
4
|
-
color: AXIS_COLORS.zAxis,
|
|
5
|
-
rectangle: 'lengthRectangle',
|
|
6
|
-
label: 'lengthLabel',
|
|
7
|
-
container: 'lengthContainer'
|
|
8
|
-
}, {
|
|
9
|
-
name: 'height',
|
|
10
|
-
color: AXIS_COLORS.yAxis,
|
|
11
|
-
rectangle: 'heightRectangle',
|
|
12
|
-
label: 'heightLabel',
|
|
13
|
-
container: 'widthContainer'
|
|
14
|
-
}, {
|
|
15
|
-
name: 'width',
|
|
16
|
-
color: AXIS_COLORS.xAxis,
|
|
17
|
-
rectangle: 'widthRectangle',
|
|
18
|
-
label: 'widthLabel',
|
|
19
|
-
container: 'heightContainer'
|
|
20
|
-
}];
|
package/dist/enums/exclusions.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export const exclusionMaterials = ['colorShader', 'default material', 'gridMat', 'ground', 'skyBox', 'boundingMaterial', 'voxelization', 'voxelSlabDebug'];
|
|
2
|
-
export const exclusionMeshes = ['xAxisMesh', 'yAxisMesh', 'zAxisMesh', 'mirrorGround', 'ground', 'hdrSkyBox', 'boundingMesh', 'lengthContainer', 'widthContainer', 'heightContainer'];
|
|
3
|
-
export const exclusionGUIs = ['guiDragSelectBox', 'lengthRectangle', 'lengthLabel', 'lengthContainer', 'widthRectangle', 'widthLabel', 'widthContainer', 'heightRectangle', 'heightLabel', 'heightContainer'];
|
|
4
|
-
export const exclusionTNodes = ['xAxis', 'yAxis', 'zAxis', 'multiMeshTransforms', 'singleMeshTransforms'];
|
package/dist/enums/formats.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DRAG_DROP_FORMATS = ['gltf', 'glb'];
|
package/dist/enums/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as BABYLON from 'babylonjs';
|
|
2
|
-
const toRadians = value => BABYLON.Tools.ToRadians(value || 0);
|
|
3
|
-
export const orthoOptions = {
|
|
4
|
-
orthoLeft: {
|
|
5
|
-
alpha: 0,
|
|
6
|
-
beta: toRadians(90)
|
|
7
|
-
},
|
|
8
|
-
orthoRight: {
|
|
9
|
-
alpha: toRadians(180),
|
|
10
|
-
beta: toRadians(90)
|
|
11
|
-
},
|
|
12
|
-
orthoFront: {
|
|
13
|
-
alpha: toRadians(90),
|
|
14
|
-
beta: toRadians(90)
|
|
15
|
-
},
|
|
16
|
-
orthoBack: {
|
|
17
|
-
alpha: toRadians(270),
|
|
18
|
-
beta: toRadians(90)
|
|
19
|
-
},
|
|
20
|
-
orthoTop: {
|
|
21
|
-
alpha: toRadians(90),
|
|
22
|
-
beta: 0
|
|
23
|
-
},
|
|
24
|
-
orthoBottom: {
|
|
25
|
-
alpha: toRadians(90),
|
|
26
|
-
beta: toRadians(180)
|
|
27
|
-
}
|
|
28
|
-
};
|
package/dist/enums/scaleUnits.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export const scaleUnits = [{
|
|
2
|
-
name: 'millimeter',
|
|
3
|
-
abbreviation: 'mm',
|
|
4
|
-
scaleFactor: 0.001
|
|
5
|
-
}, {
|
|
6
|
-
name: 'centimeter',
|
|
7
|
-
abbreviation: 'cm',
|
|
8
|
-
scaleFactor: 0.01
|
|
9
|
-
}, {
|
|
10
|
-
name: 'meter',
|
|
11
|
-
abbreviation: 'm',
|
|
12
|
-
scaleFactor: 1
|
|
13
|
-
}, {
|
|
14
|
-
name: 'inch',
|
|
15
|
-
abbreviation: 'in',
|
|
16
|
-
scaleFactor: 0.0254
|
|
17
|
-
}, {
|
|
18
|
-
name: 'foot',
|
|
19
|
-
abbreviation: 'ft',
|
|
20
|
-
scaleFactor: 0.3048
|
|
21
|
-
}, {
|
|
22
|
-
name: 'yard',
|
|
23
|
-
abbreviation: 'yd',
|
|
24
|
-
scaleFactor: 0.9144
|
|
25
|
-
}];
|
package/dist/enums/shortcuts.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { removeFromViewport } from '../helpers';
|
|
2
|
-
import { toggleInspector, toggleSafeFrame, focusCamera, toggleRotateWidget, toggleMoveWidget, hideSelected, unhideAll, toggleCulling, modelToOrigin, toggleScaleWidget, toggleBoundingBoxWidget, toggleOrthographicViews, toggleTurntable } from '../actions';
|
|
3
|
-
const deletePayload = {
|
|
4
|
-
payload: {
|
|
5
|
-
deleteSelectedMesh: true
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
export const shortcuts = {
|
|
9
|
-
camera: [{
|
|
10
|
-
name: 'focusCamera',
|
|
11
|
-
key: 'C',
|
|
12
|
-
action: () => focusCamera?.()
|
|
13
|
-
}, {
|
|
14
|
-
name: 'toggleSafeFrame',
|
|
15
|
-
key: 'F',
|
|
16
|
-
action: () => toggleSafeFrame?.()
|
|
17
|
-
}, {
|
|
18
|
-
name: 'orthoLeft',
|
|
19
|
-
key: '1',
|
|
20
|
-
action: e => toggleOrthographicViews(e, 'orthoLeft')
|
|
21
|
-
}, {
|
|
22
|
-
name: 'orthoRight',
|
|
23
|
-
key: '2',
|
|
24
|
-
action: e => toggleOrthographicViews(e, 'orthoRight')
|
|
25
|
-
}, {
|
|
26
|
-
name: 'orthoFront',
|
|
27
|
-
key: '3',
|
|
28
|
-
action: e => toggleOrthographicViews(e, 'orthoFront')
|
|
29
|
-
}, {
|
|
30
|
-
name: 'orthoBack',
|
|
31
|
-
key: '4',
|
|
32
|
-
action: e => toggleOrthographicViews(e, 'orthoBack')
|
|
33
|
-
}, {
|
|
34
|
-
name: 'orthoTop',
|
|
35
|
-
key: '5',
|
|
36
|
-
action: e => toggleOrthographicViews(e, 'orthoTop')
|
|
37
|
-
}, {
|
|
38
|
-
name: 'orthoBottom',
|
|
39
|
-
key: '6',
|
|
40
|
-
action: e => toggleOrthographicViews(e, 'orthoBottom')
|
|
41
|
-
}],
|
|
42
|
-
utilities: [{
|
|
43
|
-
name: 'inspector',
|
|
44
|
-
key: 'N',
|
|
45
|
-
action: () => toggleInspector?.()
|
|
46
|
-
}, {
|
|
47
|
-
name: 'turntable',
|
|
48
|
-
key: '/',
|
|
49
|
-
action: (e, override) => toggleTurntable?.(override)
|
|
50
|
-
}],
|
|
51
|
-
viewport: [{
|
|
52
|
-
name: 'moveWidget',
|
|
53
|
-
key: 'M',
|
|
54
|
-
action: () => toggleMoveWidget?.()
|
|
55
|
-
}, {
|
|
56
|
-
name: 'rotateWidget',
|
|
57
|
-
key: 'R',
|
|
58
|
-
action: () => toggleRotateWidget?.()
|
|
59
|
-
}, {
|
|
60
|
-
name: 'scaleWidget',
|
|
61
|
-
key: 'S',
|
|
62
|
-
action: () => toggleScaleWidget?.()
|
|
63
|
-
}, {
|
|
64
|
-
name: 'hideSelected',
|
|
65
|
-
key: 'H',
|
|
66
|
-
action: () => hideSelected?.()
|
|
67
|
-
}, {
|
|
68
|
-
name: 'unhideAll',
|
|
69
|
-
key: 'U',
|
|
70
|
-
action: () => unhideAll?.()
|
|
71
|
-
}, {
|
|
72
|
-
name: 'boundingBox',
|
|
73
|
-
key: 'B',
|
|
74
|
-
action: () => toggleBoundingBoxWidget?.()
|
|
75
|
-
}, {
|
|
76
|
-
name: 'deleteSelected',
|
|
77
|
-
key: 'Delete',
|
|
78
|
-
action: () => removeFromViewport(deletePayload)
|
|
79
|
-
}],
|
|
80
|
-
model: [{
|
|
81
|
-
name: 'toggleCulling',
|
|
82
|
-
key: 'c',
|
|
83
|
-
action: () => toggleCulling?.()
|
|
84
|
-
}, {
|
|
85
|
-
name: 'modelToOrigin',
|
|
86
|
-
key: 'O',
|
|
87
|
-
action: () => modelToOrigin?.()
|
|
88
|
-
}]
|
|
89
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as BABYLON from 'babylonjs';
|
|
2
|
-
import { newVector } from './utilityHelpers';
|
|
3
|
-
import { scene, engine, canvas, selectedMeshes, getParamOfSelectedMeshes, getUserMeshes, defaultCameraPosition, getBoundingMeshData } from '../helpers';
|
|
4
|
-
import { CAMERAS, MESH_PARAMS } from '../constants';
|
|
5
|
-
import { focusCamera, toggleTurntable } from '../actions';
|
|
6
|
-
import { orthoOptions, ratios } from '../enums';
|
|
7
|
-
import _ from 'lodash';
|
|
8
|
-
export const newCamera = (name, location, type, meta = {}) => {
|
|
9
|
-
const defaultName = `camera_${getSceneCameras().length + 1}`;
|
|
10
|
-
if (type === CAMERAS.ArcRotateCamera) {
|
|
11
|
-
return new BABYLON.ArcRotateCamera(name || defaultName, meta.alpha || 0, meta.beta || 0, meta.radius || 0, newVector(location.x, location.y, location.z), scene);
|
|
12
|
-
}
|
|
13
|
-
if (CAMERAS[type] && typeof BABYLON[type] === 'function') {
|
|
14
|
-
return new BABYLON[type](name || defaultName, newVector(location.x, location.y, location.z), scene);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export const prepareCamera = () => {
|
|
18
|
-
const camera = scene.activeCamera;
|
|
19
|
-
const canvasDimensions = engine?.getRenderingCanvasClientRect?.();
|
|
20
|
-
const width = canvasDimensions?.width || ratios.square.value;
|
|
21
|
-
const height = canvasDimensions?.height || ratios.square.value;
|
|
22
|
-
const aspect = height / width;
|
|
23
|
-
const userMeshes = getUserMeshes();
|
|
24
|
-
camera.orthoLeft = -camera.radius;
|
|
25
|
-
camera.orthoTop = camera.radius * aspect;
|
|
26
|
-
camera.orthoRight = camera.radius;
|
|
27
|
-
camera.orthoBottom = -camera.radius * aspect;
|
|
28
|
-
camera.lowerRadiusLimit = 1;
|
|
29
|
-
camera.upperRadiusLimit = 5000;
|
|
30
|
-
camera.minZ = 0.1;
|
|
31
|
-
camera.setPosition?.(defaultCameraPosition());
|
|
32
|
-
camera.setTarget(BABYLON.Vector3.Zero());
|
|
33
|
-
camera.attachControl(canvas, true);
|
|
34
|
-
_.isEmpty(userMeshes) ? toggleTurntable(true) : focusCamera();
|
|
35
|
-
};
|
|
36
|
-
export const prepareMaterialCamera = () => {
|
|
37
|
-
const camera = scene.activeCamera;
|
|
38
|
-
const sphere = scene.getMeshById('node0');
|
|
39
|
-
camera.position = defaultCameraPosition();
|
|
40
|
-
if (sphere) {
|
|
41
|
-
const primarySurfaces = [sphere];
|
|
42
|
-
const meshCenter = getBoundingMeshData(primarySurfaces).center;
|
|
43
|
-
camera.setTarget(meshCenter);
|
|
44
|
-
camera.alpha = 1.57;
|
|
45
|
-
camera.beta = 1.65;
|
|
46
|
-
camera.lowerRadiusLimit = 0.3239;
|
|
47
|
-
camera.upperRadiusLimit = 5000;
|
|
48
|
-
camera.minZ = 0.1;
|
|
49
|
-
camera.maxZ = 10000;
|
|
50
|
-
camera.radius = 4;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
export const toggleCameraMode = (orthoCamera, requestedMode) => {
|
|
54
|
-
const camera = scene.activeCamera;
|
|
55
|
-
const babylonOrthographic = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
|
|
56
|
-
const ratio = canvas.height / canvas.width;
|
|
57
|
-
if (!camera) return;
|
|
58
|
-
camera.mode = requestedMode;
|
|
59
|
-
if (camera.mode === babylonOrthographic) {
|
|
60
|
-
if (!_.isEmpty(selectedMeshes)) {
|
|
61
|
-
camera.target = getParamOfSelectedMeshes(MESH_PARAMS.center);
|
|
62
|
-
}
|
|
63
|
-
camera.alpha = orthoOptions[orthoCamera].alpha;
|
|
64
|
-
camera.beta = orthoOptions[orthoCamera].beta;
|
|
65
|
-
|
|
66
|
-
// Zooming
|
|
67
|
-
camera.lowerRadiusLimit = 5;
|
|
68
|
-
camera.upperRadiusLimit = 5000;
|
|
69
|
-
camera.minZ = 0.1;
|
|
70
|
-
camera.maxZ = 10000;
|
|
71
|
-
camera.wheelDeltaPercentage = 0.01;
|
|
72
|
-
let oldRadius = camera.radius;
|
|
73
|
-
scene.onBeforeRenderObservable.add(() => {
|
|
74
|
-
if (oldRadius !== camera.radius) {
|
|
75
|
-
const radiusChangeRatio = camera.radius / oldRadius;
|
|
76
|
-
camera.orthoLeft *= radiusChangeRatio;
|
|
77
|
-
camera.orthoRight *= radiusChangeRatio;
|
|
78
|
-
oldRadius = camera.radius;
|
|
79
|
-
camera.orthoTop = camera.orthoRight * ratio;
|
|
80
|
-
camera.orthoBottom = camera.orthoLeft * ratio;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
focusCamera?.();
|
|
85
|
-
};
|
|
86
|
-
export const getSceneCameras = () => scene.cameras;
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { scene } from './initHelpers';
|
|
2
|
-
import { newMetaDataEntry, newTexture } from './utilityHelpers';
|
|
3
|
-
import { selectedMeshes } from './viewportHelpers';
|
|
4
|
-
import { singleMeshTNode, toDegrees } from '../helpers';
|
|
5
|
-
import { MESSAGE_TYPES } from '../constants';
|
|
6
|
-
import { reactProps as props } from '../Canvas';
|
|
7
|
-
import _ from 'lodash';
|
|
8
|
-
export const addToMaterial = inboundData => {
|
|
9
|
-
const {
|
|
10
|
-
payload
|
|
11
|
-
} = inboundData;
|
|
12
|
-
const {
|
|
13
|
-
id,
|
|
14
|
-
albedoTexture,
|
|
15
|
-
metallicTexture,
|
|
16
|
-
microSurfaceTexture,
|
|
17
|
-
emissiveTexture,
|
|
18
|
-
bumpTexture
|
|
19
|
-
} = payload;
|
|
20
|
-
const material = scene.getMaterialByName(id, true);
|
|
21
|
-
if (material) {
|
|
22
|
-
// Basic attribute textures.
|
|
23
|
-
if (_.isString(albedoTexture)) material.albedoTexture = newTexture(albedoTexture);
|
|
24
|
-
if (_.isString(metallicTexture)) material.metallicTexture = newTexture(metallicTexture);
|
|
25
|
-
if (_.isString(microSurfaceTexture)) material.microSurfaceTexture = newTexture(microSurfaceTexture);
|
|
26
|
-
if (_.isString(emissiveTexture)) material.emissiveTexture = newTexture(emissiveTexture);
|
|
27
|
-
if (_.isString(bumpTexture)) material.bumpTexture = newTexture(bumpTexture);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const addToMesh = inboundData => {
|
|
31
|
-
const {
|
|
32
|
-
payload
|
|
33
|
-
} = inboundData;
|
|
34
|
-
const {
|
|
35
|
-
id
|
|
36
|
-
} = payload;
|
|
37
|
-
if (_.isEmpty(selectedMeshes) || selectedMeshes.length > 1) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const mesh = selectedMeshes[0];
|
|
41
|
-
if (mesh) {
|
|
42
|
-
// Custom user mesh positions.
|
|
43
|
-
const duplicate = scene.metadata?.userMeshPositions?.find(meshPos => meshPos.meshId === mesh.id && meshPos.positionId === id);
|
|
44
|
-
if (_.isString(id) && !duplicate) {
|
|
45
|
-
const {
|
|
46
|
-
position,
|
|
47
|
-
rotation,
|
|
48
|
-
scaling
|
|
49
|
-
} = singleMeshTNode;
|
|
50
|
-
const [tx, ty, tz] = position.asArray();
|
|
51
|
-
const [rx, ry, rz] = rotation.asArray().map(val => toDegrees(val * -1));
|
|
52
|
-
const [sx, sy, sz] = scaling.asArray();
|
|
53
|
-
const positionObj = {
|
|
54
|
-
meshId: mesh.id,
|
|
55
|
-
positionId: id,
|
|
56
|
-
tx,
|
|
57
|
-
ty,
|
|
58
|
-
tz,
|
|
59
|
-
rx,
|
|
60
|
-
ry,
|
|
61
|
-
rz,
|
|
62
|
-
sx,
|
|
63
|
-
sy,
|
|
64
|
-
sz
|
|
65
|
-
};
|
|
66
|
-
const updatedPositions = [...(scene.metadata?.userMeshPositions || {}), positionObj];
|
|
67
|
-
const selectedUserMeshPositions = scene.metadata.selectedUserMeshPositions;
|
|
68
|
-
const filteredPositions = selectedUserMeshPositions.filter(pos => pos.meshId !== mesh.id);
|
|
69
|
-
filteredPositions.push(positionObj);
|
|
70
|
-
newMetaDataEntry('userMeshPositions', updatedPositions.filter(item => item));
|
|
71
|
-
newMetaDataEntry('selectedUserMeshPositions', filteredPositions);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
export const addToCamera = inboundData => {
|
|
76
|
-
const {
|
|
77
|
-
payload
|
|
78
|
-
} = inboundData;
|
|
79
|
-
const {
|
|
80
|
-
id
|
|
81
|
-
} = payload;
|
|
82
|
-
const camera = scene.activeCamera;
|
|
83
|
-
if (camera) {
|
|
84
|
-
// Custom user camera views.
|
|
85
|
-
const duplicate = scene.metadata?.userCameraViews.find(cameraPos => cameraPos.id === id);
|
|
86
|
-
if (_.isString(id) && !duplicate) {
|
|
87
|
-
const {
|
|
88
|
-
position,
|
|
89
|
-
rotation,
|
|
90
|
-
target
|
|
91
|
-
} = scene.activeCamera;
|
|
92
|
-
const [tx, ty, tz] = [position.x, position.y, position.z];
|
|
93
|
-
const [rx, ry, rz] = [rotation.x, rotation.y, rotation.z];
|
|
94
|
-
const [tarX, tarY, tarZ] = [target.x, target.y, target.z];
|
|
95
|
-
const updatedPositions = [...(scene.metadata?.userCameraViews || []), {
|
|
96
|
-
id,
|
|
97
|
-
tx,
|
|
98
|
-
ty,
|
|
99
|
-
tz,
|
|
100
|
-
rx,
|
|
101
|
-
ry,
|
|
102
|
-
rz,
|
|
103
|
-
tarX,
|
|
104
|
-
tarY,
|
|
105
|
-
tarZ
|
|
106
|
-
}];
|
|
107
|
-
newMetaDataEntry('userCameraViews', updatedPositions.filter(item => item));
|
|
108
|
-
newMetaDataEntry('selectedUserCameraView', {
|
|
109
|
-
id,
|
|
110
|
-
tx,
|
|
111
|
-
ty,
|
|
112
|
-
tz,
|
|
113
|
-
rx,
|
|
114
|
-
ry,
|
|
115
|
-
rz,
|
|
116
|
-
tarX,
|
|
117
|
-
tarY,
|
|
118
|
-
tarZ
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
export const addToEnvironment = inboundData => {
|
|
124
|
-
const {
|
|
125
|
-
payload
|
|
126
|
-
} = inboundData;
|
|
127
|
-
const {
|
|
128
|
-
id,
|
|
129
|
-
url
|
|
130
|
-
} = payload;
|
|
131
|
-
const skyBox = scene.getMaterialById('skyBox', true);
|
|
132
|
-
if (skyBox) {
|
|
133
|
-
// Add custom user environment.
|
|
134
|
-
const duplicate = scene.metadata?.userEnvironments.find(env => env.id === id);
|
|
135
|
-
const isNotDefault = url !== scene.metadata.defaultEnvironment;
|
|
136
|
-
const isValid = isNotDefault && _.isString(id) && _.isString(url) && !duplicate;
|
|
137
|
-
if (isValid) {
|
|
138
|
-
const message = 'Adding custom environment...';
|
|
139
|
-
const clearExisting = true;
|
|
140
|
-
const isUserFile = true;
|
|
141
|
-
const config = {
|
|
142
|
-
type: MESSAGE_TYPES.loading,
|
|
143
|
-
showModal: true,
|
|
144
|
-
closeButton: false
|
|
145
|
-
};
|
|
146
|
-
props.addNotification?.([{
|
|
147
|
-
message,
|
|
148
|
-
config
|
|
149
|
-
}], clearExisting);
|
|
150
|
-
newTexture(url, isUserFile);
|
|
151
|
-
const updatedEnvironments = [...(scene.metadata?.userEnvironments || {}), {
|
|
152
|
-
id,
|
|
153
|
-
url
|
|
154
|
-
}];
|
|
155
|
-
newMetaDataEntry('userEnvironments', updatedEnvironments.filter(item => item));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
export const addToViewport = () => {
|
|
160
|
-
// Add functions here...
|
|
161
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { UPDATABLE_ITEMS } from '../constants';
|
|
2
|
-
import { updateMaterial, addToMaterial, removeFromMaterial, updateMesh, addToMesh, removeFromMesh, updateCamera, addToCamera, removeFromCamera, updateEnvironment, addToEnvironment, removeFromEnvironment, updateViewport, addToViewport, removeFromViewport, serializeScene, updatePublish, newMetaDataEntry, buildMeshIdArray, updateLighting } from '../helpers';
|
|
3
|
-
import { reactProps as props } from '../Canvas';
|
|
4
|
-
export const updateItem = inboundData => {
|
|
5
|
-
const {
|
|
6
|
-
type,
|
|
7
|
-
method
|
|
8
|
-
} = inboundData;
|
|
9
|
-
const types = Object.keys(UPDATABLE_ITEMS);
|
|
10
|
-
const isValidType = types.includes(type);
|
|
11
|
-
const hidden = true;
|
|
12
|
-
if (isValidType) {
|
|
13
|
-
switch (type) {
|
|
14
|
-
case UPDATABLE_ITEMS.material:
|
|
15
|
-
if (method === 'update') updateMaterial(inboundData);
|
|
16
|
-
if (method === 'add') addToMaterial(inboundData);
|
|
17
|
-
if (method === 'remove') removeFromMaterial(inboundData);
|
|
18
|
-
break;
|
|
19
|
-
case UPDATABLE_ITEMS.mesh:
|
|
20
|
-
if (method === 'update') updateMesh(inboundData);
|
|
21
|
-
if (method === 'add') addToMesh(inboundData);
|
|
22
|
-
if (method === 'remove') removeFromMesh(inboundData);
|
|
23
|
-
break;
|
|
24
|
-
case UPDATABLE_ITEMS.camera:
|
|
25
|
-
if (method === 'update') updateCamera(inboundData);
|
|
26
|
-
if (method === 'add') addToCamera(inboundData);
|
|
27
|
-
if (method === 'remove') removeFromCamera(inboundData);
|
|
28
|
-
break;
|
|
29
|
-
case UPDATABLE_ITEMS.environment:
|
|
30
|
-
if (method === 'update') updateEnvironment(inboundData);
|
|
31
|
-
if (method === 'add') addToEnvironment(inboundData);
|
|
32
|
-
if (method === 'remove') removeFromEnvironment(inboundData);
|
|
33
|
-
break;
|
|
34
|
-
case UPDATABLE_ITEMS.viewport:
|
|
35
|
-
if (method === 'update') updateViewport(inboundData);
|
|
36
|
-
if (method === 'add') addToViewport(inboundData);
|
|
37
|
-
if (method === 'remove') removeFromViewport(inboundData);
|
|
38
|
-
break;
|
|
39
|
-
case UPDATABLE_ITEMS.publish:
|
|
40
|
-
if (method === 'update') updatePublish(inboundData);
|
|
41
|
-
break;
|
|
42
|
-
case UPDATABLE_ITEMS.lighting:
|
|
43
|
-
if (method === 'update') updateLighting(inboundData);
|
|
44
|
-
break;
|
|
45
|
-
default:
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
newMetaDataEntry('hiddenMeshes', buildMeshIdArray(hidden));
|
|
49
|
-
props.setSerializedData?.(serializeScene());
|
|
50
|
-
props.clearUpdateData?.();
|
|
51
|
-
}
|
|
52
|
-
};
|