@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,230 +0,0 @@
|
|
|
1
|
-
import { scene, newMetaDataEntry, selectedMeshes, updateCamera, updateEnvironment, buildMaterialsArray, buildSelectedMaterialArray, serializeScene } from '../helpers';
|
|
2
|
-
import { reactProps as props } from '../Canvas';
|
|
3
|
-
import { deleteSelected } from '../actions';
|
|
4
|
-
import { TRANSPARENCY_MODES } from '../constants';
|
|
5
|
-
import * as BABYLON from 'babylonjs';
|
|
6
|
-
import _ from 'lodash';
|
|
7
|
-
const removeChannelFromTexture = (image, channel) => {
|
|
8
|
-
const imageHeight = image?.naturalHeight ?? 0;
|
|
9
|
-
const imageWidth = image?.naturalWidth ?? 0;
|
|
10
|
-
let imageData;
|
|
11
|
-
const maxHeight = Math.max(...[imageHeight, 1024]);
|
|
12
|
-
const maxWidth = Math.max(...[imageWidth, 1024]);
|
|
13
|
-
const canvas = document.createElement('canvas');
|
|
14
|
-
const ctx = canvas.getContext('2d');
|
|
15
|
-
canvas.width = maxWidth;
|
|
16
|
-
canvas.height = maxHeight;
|
|
17
|
-
if (image) {
|
|
18
|
-
ctx.drawImage(image, 0, 0, maxWidth, maxHeight);
|
|
19
|
-
imageData = ctx.getImageData(0, 0, maxWidth, maxHeight).data;
|
|
20
|
-
}
|
|
21
|
-
const combinedImageData = ctx.createImageData(maxWidth, maxHeight);
|
|
22
|
-
const combinedData = combinedImageData.data;
|
|
23
|
-
for (let i = 0; i < combinedData.length; i += 4) {
|
|
24
|
-
combinedData[i] = channel === 'R' ? 0 : imageData[i];
|
|
25
|
-
combinedData[i + 1] = channel === 'G' ? 0 : imageData[i + 1];
|
|
26
|
-
combinedData[i + 2] = channel === 'B' ? 0 : imageData[i + 2];
|
|
27
|
-
combinedData[i + 3] = channel === 'A' ? 255 : imageData[i + 3];
|
|
28
|
-
}
|
|
29
|
-
ctx.putImageData(combinedImageData, 0, 0);
|
|
30
|
-
return canvas.toDataURL('image/png');
|
|
31
|
-
};
|
|
32
|
-
const textureToImage = texture => {
|
|
33
|
-
return new Promise(resolve => {
|
|
34
|
-
if (!texture.readPixels()) {
|
|
35
|
-
resolve(null);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
texture.readPixels().then(pixels => {
|
|
39
|
-
const canvas = document.createElement('canvas');
|
|
40
|
-
const ctx = canvas.getContext('2d');
|
|
41
|
-
const {
|
|
42
|
-
width,
|
|
43
|
-
height
|
|
44
|
-
} = texture.getSize();
|
|
45
|
-
canvas.width = width;
|
|
46
|
-
canvas.height = height;
|
|
47
|
-
const img = new Image();
|
|
48
|
-
const imageData = ctx.createImageData(width, height);
|
|
49
|
-
imageData.data.set(new Uint8ClampedArray(pixels));
|
|
50
|
-
ctx.putImageData(imageData, 0, 0);
|
|
51
|
-
img.onload = () => {
|
|
52
|
-
resolve(img);
|
|
53
|
-
};
|
|
54
|
-
img.onerror = () => {
|
|
55
|
-
resolve(null);
|
|
56
|
-
};
|
|
57
|
-
img.src = canvas.toDataURL();
|
|
58
|
-
}).catch(() => {
|
|
59
|
-
resolve(null);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
export const removeFromMaterial = inboundData => {
|
|
64
|
-
const {
|
|
65
|
-
payload
|
|
66
|
-
} = inboundData;
|
|
67
|
-
const {
|
|
68
|
-
id,
|
|
69
|
-
removeAlbedoTexture,
|
|
70
|
-
removeMetallicTexture,
|
|
71
|
-
removeMicroSurfaceTexture,
|
|
72
|
-
removeEmissiveTexture,
|
|
73
|
-
removeBumpTexture,
|
|
74
|
-
removeOpacityTexture,
|
|
75
|
-
removeRoughnessTexture,
|
|
76
|
-
removeAmbientTexture
|
|
77
|
-
} = payload;
|
|
78
|
-
const material = scene.getMaterialByName(id, true);
|
|
79
|
-
if (material) {
|
|
80
|
-
// Basic attribute textures.
|
|
81
|
-
if (removeAlbedoTexture) {
|
|
82
|
-
const isStencil = material.transparencyType === TRANSPARENCY_MODES.stencil;
|
|
83
|
-
if (isStencil) {
|
|
84
|
-
material.albedoTexture.hasAlpha = false;
|
|
85
|
-
material.albedoTexture.useAlphaFromAlbedoTexture = false;
|
|
86
|
-
material.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
87
|
-
material.transparencyType = TRANSPARENCY_MODES.simple;
|
|
88
|
-
}
|
|
89
|
-
material.albedoTexture?.dispose();
|
|
90
|
-
material.albedoTexture = null;
|
|
91
|
-
}
|
|
92
|
-
if (removeMetallicTexture) {
|
|
93
|
-
if (material.metallicTexture) {
|
|
94
|
-
textureToImage(material.metallicTexture).then(data => {
|
|
95
|
-
const updatedTexture = removeChannelFromTexture(data, 'B');
|
|
96
|
-
material.metallicTexture.updateURL(updatedTexture);
|
|
97
|
-
newMetaDataEntry('materials', buildMaterialsArray());
|
|
98
|
-
newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
|
|
99
|
-
props.clearNotifications?.();
|
|
100
|
-
props.setSerializedData?.(serializeScene());
|
|
101
|
-
}).catch(() => {
|
|
102
|
-
console.log('Failed to remove metallic texture');
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (removeMicroSurfaceTexture) {
|
|
107
|
-
material.microSurfaceTexture?.dispose();
|
|
108
|
-
material.microSurfaceTexture = null;
|
|
109
|
-
}
|
|
110
|
-
if (removeEmissiveTexture) {
|
|
111
|
-
material.emissiveTexture?.dispose();
|
|
112
|
-
material.emissiveTexture = null;
|
|
113
|
-
}
|
|
114
|
-
if (removeBumpTexture) {
|
|
115
|
-
material.bumpTexture?.dispose();
|
|
116
|
-
material.bumpTexture = null;
|
|
117
|
-
}
|
|
118
|
-
if (removeOpacityTexture) {
|
|
119
|
-
material.opacityTexture?.dispose();
|
|
120
|
-
material.opacityTexture = null;
|
|
121
|
-
}
|
|
122
|
-
if (removeAmbientTexture) {
|
|
123
|
-
material.ambientTexture?.dispose();
|
|
124
|
-
material.ambientTexture = null;
|
|
125
|
-
}
|
|
126
|
-
if (removeRoughnessTexture) {
|
|
127
|
-
if (material.metallicTexture) {
|
|
128
|
-
textureToImage(material.metallicTexture).then(data => {
|
|
129
|
-
const updatedTexture = removeChannelFromTexture(data, 'G');
|
|
130
|
-
material.metallicTexture.updateURL(updatedTexture);
|
|
131
|
-
newMetaDataEntry('materials', buildMaterialsArray());
|
|
132
|
-
newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
|
|
133
|
-
props.clearNotifications?.();
|
|
134
|
-
props.setSerializedData?.(serializeScene());
|
|
135
|
-
}).catch(() => {
|
|
136
|
-
console.log('Failed to remove roughness texture');
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
newMetaDataEntry('materials', buildMaterialsArray());
|
|
141
|
-
newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
export const removeFromMesh = inboundData => {
|
|
145
|
-
const {
|
|
146
|
-
payload
|
|
147
|
-
} = inboundData;
|
|
148
|
-
const {
|
|
149
|
-
id
|
|
150
|
-
} = payload;
|
|
151
|
-
if (_.isString(id)) {
|
|
152
|
-
if (_.isEmpty(selectedMeshes) || selectedMeshes.length > 1) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const selectedMesh = selectedMeshes[0];
|
|
156
|
-
|
|
157
|
-
// Remove custom user mesh positions.
|
|
158
|
-
const userMeshPositions = scene.metadata?.userMeshPositions?.filter(mesh => mesh.meshId !== selectedMesh.id || mesh.positionId !== id) || [];
|
|
159
|
-
const filteredSelectedPositions = scene.metadata.selectedUserMeshPositions.filter(pos => pos.meshId !== selectedMesh.id || pos.positionId !== id);
|
|
160
|
-
const defaultPosition = userMeshPositions.find(pos => pos.meshId === selectedMesh.id && pos.positionId === 'Default');
|
|
161
|
-
filteredSelectedPositions.push(defaultPosition);
|
|
162
|
-
newMetaDataEntry('userMeshPositions', userMeshPositions);
|
|
163
|
-
newMetaDataEntry('selectedUserMeshPositions', filteredSelectedPositions);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
export const removeFromCamera = inboundData => {
|
|
167
|
-
const {
|
|
168
|
-
payload
|
|
169
|
-
} = inboundData;
|
|
170
|
-
const {
|
|
171
|
-
id
|
|
172
|
-
} = payload;
|
|
173
|
-
if (_.isString(id)) {
|
|
174
|
-
// Custom user camera views.
|
|
175
|
-
const filteredPositions = scene.metadata?.userCameraViews.filter(cameraPos => cameraPos.id !== id) || [];
|
|
176
|
-
const inboundData = {
|
|
177
|
-
payload: {
|
|
178
|
-
resetCamera: true
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
newMetaDataEntry('userCameraViews', filteredPositions);
|
|
182
|
-
updateCamera(inboundData);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
export const removeFromEnvironment = inboundData => {
|
|
186
|
-
const {
|
|
187
|
-
payload
|
|
188
|
-
} = inboundData;
|
|
189
|
-
const {
|
|
190
|
-
id
|
|
191
|
-
} = payload;
|
|
192
|
-
const userEnv = scene.metadata?.userEnvironments.find(env => env.id === id);
|
|
193
|
-
|
|
194
|
-
// remove custom user environment.
|
|
195
|
-
if (_.isString(id) && _.isString(userEnv?.url)) {
|
|
196
|
-
const filteredEnvs = scene.metadata?.userEnvironments.filter(env => env.id != id) || [];
|
|
197
|
-
const inboundData = {
|
|
198
|
-
payload: {
|
|
199
|
-
url: scene.metadata.defaultEnvironment,
|
|
200
|
-
transforms: {
|
|
201
|
-
rotation: {
|
|
202
|
-
ry: scene.metadata.environmentRotation
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
newMetaDataEntry('userEnvironments', filteredEnvs);
|
|
208
|
-
updateEnvironment(inboundData);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
export const removeFromViewport = inboundData => {
|
|
212
|
-
const {
|
|
213
|
-
payload
|
|
214
|
-
} = inboundData;
|
|
215
|
-
const {
|
|
216
|
-
deleteSelectedMesh
|
|
217
|
-
} = payload;
|
|
218
|
-
const hasSelection = selectedMeshes.length > 0;
|
|
219
|
-
|
|
220
|
-
// Delete selected mesh.
|
|
221
|
-
if (deleteSelectedMesh !== undefined && hasSelection) {
|
|
222
|
-
const multiSelection = selectedMeshes.length > 1;
|
|
223
|
-
const confirmConfig = {
|
|
224
|
-
message: `Are you sure you want to delete ${multiSelection ? 'these meshes' : 'this mesh'}?`,
|
|
225
|
-
onConfirm: () => deleteSelected(),
|
|
226
|
-
onClose: () => props.setConfirmMessage?.(null)
|
|
227
|
-
};
|
|
228
|
-
props.setConfirmMessage?.(confirmConfig);
|
|
229
|
-
}
|
|
230
|
-
};
|