@archvisioninc/canvas 3.1.5 → 3.1.7

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.
@@ -139,8 +139,6 @@ const applyUVSettings = args => {
139
139
  texture.vScale = uvYScale;
140
140
  }
141
141
  };
142
-
143
- // TODO: Future uses should support red, green, blue, and alpha channels with defaults for each
144
142
  const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
145
143
  const maintainHeight = imageToMaintain?.naturalHeight ?? 0;
146
144
  const maintainWidth = imageToMaintain?.naturalWidth ?? 0;
@@ -167,11 +165,11 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
167
165
  const combinedImageData = ctx.createImageData(maxWidth, maxHeight);
168
166
  const combinedData = combinedImageData.data;
169
167
  for (let i = 0; i < combinedData.length; i += 4) {
170
- const maintainRed = maintainData ? maintainData[i] : 0;
168
+ const maintainRed = maintainData ? maintainData[i] : 1;
171
169
  const maintainGreen = maintainData ? maintainData[i + 1] : 0;
172
170
  const maintainBlue = maintainData ? maintainData[i + 2] : 0;
173
171
  const maintainAlpha = maintainData ? maintainData[i + 3] : 255;
174
- const newRed = newData ? newData[i] : 0;
172
+ const newRed = newData ? newData[i] : 1;
175
173
  const newGreen = newData ? newData[i + 1] : 0;
176
174
  const newBlue = newData ? newData[i + 2] : 0;
177
175
  const newAlpha = newData ? newData[i + 3] : 255;
@@ -202,7 +200,7 @@ const loadImage = async file => {
202
200
  reader.readAsDataURL(file);
203
201
  });
204
202
  };
205
- const textureToImage = texture => {
203
+ const metallicTextureToImage = texture => {
206
204
  return new Promise(resolve => {
207
205
  if (!texture.readPixels()) {
208
206
  resolve(null);
@@ -393,10 +391,12 @@ export const updateMaterial = inboundData => {
393
391
  currentTexture = material.metallicTexture;
394
392
  }
395
393
  const metallicBlob = dataUrlToBlob(texture.url);
396
- Promise.all([loadImage(metallicBlob), textureToImage(currentTexture)]).then(data => {
394
+ Promise.all([loadImage(metallicBlob), metallicTextureToImage(currentTexture)]).then(data => {
397
395
  const [metallicImage, currentImage] = data;
398
396
  const combinedTexture = updateTextureChannel(currentImage, metallicImage, 'B');
399
397
  currentTexture.updateURL(combinedTexture);
398
+ material.useRoughnessFromMetallicTextureAlpha = false;
399
+ material.useMetalnessFromMetallicTextureBlue = true;
400
400
  texture.dispose();
401
401
  applyUVSettings({
402
402
  texture: material.metallicTexture,
@@ -434,10 +434,12 @@ export const updateMaterial = inboundData => {
434
434
  currentTexture = material.metallicTexture;
435
435
  }
436
436
  const roughnessBlob = dataUrlToBlob(texture.url);
437
- Promise.all([loadImage(roughnessBlob), textureToImage(currentTexture)]).then(data => {
437
+ Promise.all([loadImage(roughnessBlob), metallicTextureToImage(currentTexture)]).then(data => {
438
438
  const [roughnessImage, metallicImage] = data;
439
439
  const combinedTexture = updateTextureChannel(metallicImage, roughnessImage, 'G');
440
440
  currentTexture.updateURL(combinedTexture);
441
+ material.useRoughnessFromMetallicTextureAlpha = false;
442
+ material.useRoughnessFromMetallicTextureGreen = true;
441
443
  texture.dispose();
442
444
  applyUVSettings({
443
445
  texture: material.metallicTexture,
@@ -42,7 +42,7 @@ const resizeEngine = () => engine?.resize();
42
42
  export const initSceneObjects = () => {
43
43
  initCamera();
44
44
  initLights();
45
- initHighlightManagers();
45
+ if (!props.previewMode) initHighlightManagers();
46
46
  if (!props.previewMode) initGridGround();
47
47
  initMirrorGround();
48
48
  initGizmos();
@@ -25,6 +25,7 @@ export const serializeScene = () => {
25
25
  return serializedData;
26
26
  };
27
27
  export const addHighlightExclusion = mesh => {
28
+ if (props.previewMode) return;
28
29
  highlightManager.addExcludedMesh(mesh);
29
30
  hoverHighlightManager.addExcludedMesh(mesh);
30
31
  };
@@ -92,6 +92,7 @@ const removeSelectedMesh = selectedMesh => {
92
92
  };
93
93
  const addHoverMesh = pickedMesh => {
94
94
  if (props.integration?.meshHighlighting === false) return;
95
+ if (props.previewMode) return;
95
96
  const isSelected = selectedMeshes.includes(pickedMesh);
96
97
  removeHoverMesh();
97
98
  if (isSelected) {
@@ -107,6 +108,7 @@ const addHoverMesh = pickedMesh => {
107
108
  };
108
109
  const removeHoverMesh = () => {
109
110
  if (props.integration?.meshHighlighting === false) return;
111
+ if (props.previewMode) return;
110
112
  hoverHighlightManager.removeAllMeshes();
111
113
  if (tempMesh) {
112
114
  highlightManager.addMesh(tempMesh, highlightColor());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -177,7 +177,6 @@ const applyUVSettings = args => {
177
177
  }
178
178
  };
179
179
 
180
- // TODO: Future uses should support red, green, blue, and alpha channels with defaults for each
181
180
  const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
182
181
  const maintainHeight = imageToMaintain?.naturalHeight ?? 0;
183
182
  const maintainWidth = imageToMaintain?.naturalWidth ?? 0;
@@ -212,12 +211,12 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
212
211
  const combinedData = combinedImageData.data;
213
212
 
214
213
  for (let i = 0; i < combinedData.length; i += 4) {
215
- const maintainRed = maintainData ? maintainData[i] : 0;
214
+ const maintainRed = maintainData ? maintainData[i] : 1;
216
215
  const maintainGreen = maintainData ? maintainData[i + 1] : 0;
217
216
  const maintainBlue = maintainData ? maintainData[i + 2] : 0;
218
217
  const maintainAlpha = maintainData ? maintainData[i + 3] : 255;
219
218
 
220
- const newRed = newData ? newData[i] : 0;
219
+ const newRed = newData ? newData[i] : 1;
221
220
  const newGreen = newData ? newData[i + 1] : 0;
222
221
  const newBlue = newData ? newData[i + 2] : 0;
223
222
  const newAlpha = newData ? newData[i + 3] : 255;
@@ -231,7 +230,6 @@ const updateTextureChannel = (imageToMaintain, newImage, channelToUpdate) => {
231
230
  ctx.putImageData(combinedImageData, 0, 0);
232
231
 
233
232
  return canvas.toDataURL('image/png');
234
-
235
233
  };
236
234
 
237
235
  // eslint-disable-next-line
@@ -253,7 +251,7 @@ const loadImage = async file => {
253
251
  });
254
252
  };
255
253
 
256
- const textureToImage = texture => {
254
+ const metallicTextureToImage = texture => {
257
255
  return new Promise(resolve => {
258
256
  if (!texture.readPixels()) {
259
257
  resolve(null);
@@ -449,12 +447,14 @@ export const updateMaterial = inboundData => {
449
447
 
450
448
  Promise.all([
451
449
  loadImage(metallicBlob),
452
- textureToImage(currentTexture),
450
+ metallicTextureToImage(currentTexture),
453
451
  ])
454
452
  .then(data => {
455
453
  const [ metallicImage, currentImage ] = data;
456
454
  const combinedTexture = updateTextureChannel(currentImage, metallicImage, 'B');
457
455
  currentTexture.updateURL(combinedTexture);
456
+ material.useRoughnessFromMetallicTextureAlpha = false;
457
+ material.useMetalnessFromMetallicTextureBlue = true;
458
458
 
459
459
  texture.dispose();
460
460
  applyUVSettings({ texture: material.metallicTexture, material });
@@ -490,11 +490,13 @@ export const updateMaterial = inboundData => {
490
490
 
491
491
  const roughnessBlob = dataUrlToBlob(texture.url);
492
492
 
493
- Promise.all([ loadImage(roughnessBlob), textureToImage(currentTexture) ])
493
+ Promise.all([ loadImage(roughnessBlob), metallicTextureToImage(currentTexture) ])
494
494
  .then(data => {
495
495
  const [ roughnessImage, metallicImage ] = data;
496
496
  const combinedTexture = updateTextureChannel(metallicImage, roughnessImage, 'G');
497
497
  currentTexture.updateURL(combinedTexture);
498
+ material.useRoughnessFromMetallicTextureAlpha = false;
499
+ material.useRoughnessFromMetallicTextureGreen = true;
498
500
 
499
501
  texture.dispose();
500
502
  applyUVSettings({ texture: material.metallicTexture, material });
@@ -140,6 +140,7 @@ export const createBoundingMesh = () => {
140
140
  boundingMesh.position = nodeLocation || newVector(1, 1, 1);
141
141
  boundingMesh.isPickable = false;
142
142
 
143
+
143
144
  addHighlightExclusion(boundingMesh);
144
145
 
145
146
  return boundingMesh;
@@ -86,7 +86,7 @@ const resizeEngine = () => engine?.resize();
86
86
  export const initSceneObjects = () => {
87
87
  initCamera();
88
88
  initLights();
89
- initHighlightManagers();
89
+ if (!props.previewMode) initHighlightManagers();
90
90
  if (!props.previewMode) initGridGround();
91
91
  initMirrorGround();
92
92
  initGizmos();
@@ -55,6 +55,7 @@ export const serializeScene = () => {
55
55
  };
56
56
 
57
57
  export const addHighlightExclusion = mesh => {
58
+ if (props.previewMode) return;
58
59
  highlightManager.addExcludedMesh(mesh);
59
60
  hoverHighlightManager.addExcludedMesh(mesh);
60
61
  };
@@ -135,6 +135,7 @@ const removeSelectedMesh = selectedMesh => {
135
135
 
136
136
  const addHoverMesh = pickedMesh => {
137
137
  if (props.integration?.meshHighlighting === false) return;
138
+ if (props.previewMode) return;
138
139
 
139
140
  const isSelected = selectedMeshes.includes(pickedMesh);
140
141
 
@@ -156,6 +157,7 @@ const addHoverMesh = pickedMesh => {
156
157
 
157
158
  const removeHoverMesh = () => {
158
159
  if (props.integration?.meshHighlighting === false) return;
160
+ if (props.previewMode) return;
159
161
 
160
162
  hoverHighlightManager.removeAllMeshes();
161
163
 
@@ -130,8 +130,9 @@ const App = () => {
130
130
  const onImageLoad = args => {
131
131
  const inboundData = {
132
132
  payload: {
133
- id: 'Material Metal PBR Rich',
133
+ id: 'Material #38',
134
134
  metallicTexture: args,
135
+
135
136
  },
136
137
  };
137
138
 
@@ -149,6 +150,28 @@ const App = () => {
149
150
  });
150
151
  };
151
152
 
153
+ const onRoughnessImageLoad = args => {
154
+ const inboundData = {
155
+ payload: {
156
+ id: 'Material #38',
157
+ roughnessTexture: args,
158
+ },
159
+ };
160
+
161
+ updateMaterial(inboundData);
162
+
163
+ };
164
+
165
+ const handleRoughnessUpload = e => {
166
+ const file = e.currentTarget.files[0];
167
+ const reader = new FileReader();
168
+ reader.readAsDataURL(file);
169
+ reader.onload = () => onRoughnessImageLoad({
170
+ name: file.name,
171
+ src: reader.result,
172
+ });
173
+ };
174
+
152
175
  useEffect(() => {
153
176
  getPreviewURL();
154
177
  }, [ getPreviewURL ]);
@@ -201,7 +224,7 @@ const App = () => {
201
224
  onClick={() => {
202
225
  const inboundData = {
203
226
  payload: {
204
- id: 'Material Metal PBR Rich',
227
+ id: 'Material #38',
205
228
  removeRoughnessTexture: true,
206
229
  },
207
230
  };
@@ -213,11 +236,21 @@ const App = () => {
213
236
  </Button>
214
237
 
215
238
  <input
239
+ name='Metallic'
240
+ title='Metallic'
216
241
  type={'file'}
217
242
  onChange={handleUpload}
218
243
  accept={'image/*'}
219
244
  />
220
245
 
246
+ <input
247
+ name='Roughness'
248
+ title='Roughness'
249
+ type={'file'}
250
+ onChange={handleRoughnessUpload}
251
+ accept={'image/*'}
252
+ />
253
+
221
254
  <Button
222
255
  theme={theme}
223
256
  $selectedTheme={selectedTheme}