@archvisioninc/canvas 3.1.3 → 3.1.5

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.
@@ -1,4 +1,4 @@
1
- import { scene, newMetaDataEntry, selectedMeshes, updateCamera, updateEnvironment, buildMaterialsArray, buildSelectedMaterialArray } from '../helpers';
1
+ import { scene, newMetaDataEntry, selectedMeshes, updateCamera, updateEnvironment, buildMaterialsArray, buildSelectedMaterialArray, serializeScene } from '../helpers';
2
2
  import { reactProps as props } from '../Canvas';
3
3
  import { deleteSelected } from '../actions';
4
4
  import { TRANSPARENCY_MODES } from '../constants';
@@ -21,9 +21,9 @@ const removeChannelFromTexture = (image, channel) => {
21
21
  const combinedImageData = ctx.createImageData(maxWidth, maxHeight);
22
22
  const combinedData = combinedImageData.data;
23
23
  for (let i = 0; i < combinedData.length; i += 4) {
24
- combinedData[i] = channel === 'R' ? 255 : imageData[i];
25
- combinedData[i + 1] = channel === 'G' ? 255 : imageData[i + 1];
26
- combinedData[i + 2] = channel === 'B' ? 255 : imageData[i + 2];
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
27
  combinedData[i + 3] = channel === 'A' ? 255 : imageData[i + 3];
28
28
  }
29
29
  ctx.putImageData(combinedImageData, 0, 0);
@@ -96,6 +96,8 @@ export const removeFromMaterial = inboundData => {
96
96
  material.metallicTexture.updateURL(updatedTexture);
97
97
  newMetaDataEntry('materials', buildMaterialsArray());
98
98
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
99
+ props.clearNotifications?.();
100
+ props.setSerializedData?.(serializeScene());
99
101
  }).catch(() => {
100
102
  console.log('Failed to remove metallic texture');
101
103
  });
@@ -128,6 +130,8 @@ export const removeFromMaterial = inboundData => {
128
130
  material.metallicTexture.updateURL(updatedTexture);
129
131
  newMetaDataEntry('materials', buildMaterialsArray());
130
132
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
133
+ props.clearNotifications?.();
134
+ props.setSerializedData?.(serializeScene());
131
135
  }).catch(() => {
132
136
  console.log('Failed to remove roughness texture');
133
137
  });
@@ -151,7 +151,9 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
151
151
  const maxHeight = Math.max(...[maintainHeight, newHeight, 1024]);
152
152
  const maxWidth = Math.max(...[maintainWidth, newWidth, 1024]);
153
153
  const canvas = document.createElement('canvas');
154
- const ctx = canvas.getContext('2d');
154
+ const ctx = canvas.getContext('2d', {
155
+ willReadFrequently: true
156
+ });
155
157
  canvas.width = maxWidth;
156
158
  canvas.height = maxHeight;
157
159
  if (newImage) {
@@ -165,13 +167,13 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
165
167
  const combinedImageData = ctx.createImageData(maxWidth, maxHeight);
166
168
  const combinedData = combinedImageData.data;
167
169
  for (let i = 0; i < combinedData.length; i += 4) {
168
- const maintainRed = maintainData ? maintainData[i] : 255;
169
- const maintainGreen = maintainData ? maintainData[i + 1] : 255;
170
- const maintainBlue = maintainData ? maintainData[i + 2] : 255;
170
+ const maintainRed = maintainData ? maintainData[i] : 0;
171
+ const maintainGreen = maintainData ? maintainData[i + 1] : 0;
172
+ const maintainBlue = maintainData ? maintainData[i + 2] : 0;
171
173
  const maintainAlpha = maintainData ? maintainData[i + 3] : 255;
172
- const newRed = newData ? newData[i] : 255;
173
- const newGreen = newData ? newData[i + 1] : 255;
174
- const newBlue = newData ? newData[i + 2] : 255;
174
+ const newRed = newData ? newData[i] : 0;
175
+ const newGreen = newData ? newData[i + 1] : 0;
176
+ const newBlue = newData ? newData[i + 2] : 0;
175
177
  const newAlpha = newData ? newData[i + 3] : 255;
176
178
  combinedData[i] = channelToUpdate === 'R' ? newRed : maintainRed;
177
179
  combinedData[i + 1] = channelToUpdate === 'G' ? newGreen : maintainGreen;
@@ -402,6 +404,8 @@ export const updateMaterial = inboundData => {
402
404
  });
403
405
  newMetaDataEntry('materials', buildMaterialsArray());
404
406
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
407
+ props.clearNotifications?.();
408
+ props.setSerializedData?.(serializeScene());
405
409
  }).catch(err => {
406
410
  console.log(`Error updating the roughness texture of material: ${material.name}`);
407
411
  console.log({
@@ -441,6 +445,8 @@ export const updateMaterial = inboundData => {
441
445
  });
442
446
  newMetaDataEntry('materials', buildMaterialsArray());
443
447
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
448
+ props.clearNotifications?.();
449
+ props.setSerializedData?.(serializeScene());
444
450
  }).catch(err => {
445
451
  console.log(`Error updating the roughness texture of material: ${material.name}`);
446
452
  console.log({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -6,6 +6,7 @@ import {
6
6
  updateEnvironment,
7
7
  buildMaterialsArray,
8
8
  buildSelectedMaterialArray,
9
+ serializeScene,
9
10
  } from '../helpers';
10
11
  import { reactProps as props } from '../Canvas';
11
12
  import { deleteSelected } from '../actions';
@@ -38,9 +39,9 @@ const removeChannelFromTexture = (image, channel) => {
38
39
  const combinedData = combinedImageData.data;
39
40
 
40
41
  for (let i = 0; i < combinedData.length; i += 4) {
41
- combinedData[i] = channel === 'R' ? 255 : imageData[i];
42
- combinedData[i + 1] = channel === 'G' ? 255 : imageData[i + 1];
43
- combinedData[i + 2] = channel === 'B' ? 255 : imageData[i + 2];
42
+ combinedData[i] = channel === 'R' ? 0 : imageData[i];
43
+ combinedData[i + 1] = channel === 'G' ? 0 : imageData[i + 1];
44
+ combinedData[i + 2] = channel === 'B' ? 0 : imageData[i + 2];
44
45
  combinedData[i + 3] = channel === 'A' ? 255 : imageData[i + 3];
45
46
  }
46
47
 
@@ -129,6 +130,8 @@ export const removeFromMaterial = inboundData => {
129
130
  material.metallicTexture.updateURL(updatedTexture);
130
131
  newMetaDataEntry('materials', buildMaterialsArray());
131
132
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
133
+ props.clearNotifications?.();
134
+ props.setSerializedData?.(serializeScene());
132
135
  })
133
136
  .catch(() => {
134
137
  console.log('Failed to remove metallic texture');
@@ -167,6 +170,8 @@ export const removeFromMaterial = inboundData => {
167
170
  material.metallicTexture.updateURL(updatedTexture);
168
171
  newMetaDataEntry('materials', buildMaterialsArray());
169
172
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
173
+ props.clearNotifications?.();
174
+ props.setSerializedData?.(serializeScene());
170
175
  })
171
176
  .catch(() => {
172
177
  console.log('Failed to remove roughness texture');
@@ -192,7 +192,8 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
192
192
 
193
193
  const canvas = document.createElement('canvas');
194
194
 
195
- const ctx = canvas.getContext('2d');
195
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
196
+
196
197
 
197
198
  canvas.width = maxWidth;
198
199
  canvas.height = maxHeight;
@@ -211,14 +212,14 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
211
212
  const combinedData = combinedImageData.data;
212
213
 
213
214
  for (let i = 0; i < combinedData.length; i += 4) {
214
- const maintainRed = maintainData ? maintainData[i] : 255;
215
- const maintainGreen = maintainData ? maintainData[i + 1] : 255;
216
- const maintainBlue = maintainData ? maintainData[i + 2] : 255;
215
+ const maintainRed = maintainData ? maintainData[i] : 0;
216
+ const maintainGreen = maintainData ? maintainData[i + 1] : 0;
217
+ const maintainBlue = maintainData ? maintainData[i + 2] : 0;
217
218
  const maintainAlpha = maintainData ? maintainData[i + 3] : 255;
218
219
 
219
- const newRed = newData ? newData[i] : 255;
220
- const newGreen = newData ? newData[i + 1] : 255;
221
- const newBlue = newData ? newData[i + 2] : 255;
220
+ const newRed = newData ? newData[i] : 0;
221
+ const newGreen = newData ? newData[i + 1] : 0;
222
+ const newBlue = newData ? newData[i + 2] : 0;
222
223
  const newAlpha = newData ? newData[i + 3] : 255;
223
224
 
224
225
  combinedData[i] = channelToUpdate === 'R' ? newRed : maintainRed;
@@ -459,6 +460,8 @@ export const updateMaterial = inboundData => {
459
460
  applyUVSettings({ texture: material.metallicTexture, material });
460
461
  newMetaDataEntry('materials', buildMaterialsArray());
461
462
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
463
+ props.clearNotifications?.();
464
+ props.setSerializedData?.(serializeScene());
462
465
  })
463
466
  .catch(err => {
464
467
  console.log(`Error updating the roughness texture of material: ${material.name}`);
@@ -497,11 +500,13 @@ export const updateMaterial = inboundData => {
497
500
  applyUVSettings({ texture: material.metallicTexture, material });
498
501
  newMetaDataEntry('materials', buildMaterialsArray());
499
502
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
503
+ props.clearNotifications?.();
504
+ props.setSerializedData?.(serializeScene());
500
505
  })
501
- .catch(err => {
502
- console.log(`Error updating the roughness texture of material: ${material.name}`);
503
- console.log({ err });
504
- });
506
+ .catch(err => {
507
+ console.log(`Error updating the roughness texture of material: ${material.name}`);
508
+ console.log({ err });
509
+ });
505
510
 
506
511
  }
507
512
 
@@ -176,7 +176,10 @@ const App = () => {
176
176
  updateData={null}
177
177
  reinitialize={null}
178
178
  defaultEnvironments={ENVIRONMENTS.defaultEnvironments}
179
- setSerializedData={payload => setSerializedData(payload)}
179
+ setSerializedData={payload => {
180
+ console.log(payload);
181
+ setSerializedData(payload);
182
+ }}
180
183
  clearUpdateData={_.noop}
181
184
  toDownload={false}
182
185
  exportModel={exportModel}