@archvisioninc/canvas 3.1.4 → 3.1.6

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.
@@ -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);
@@ -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,13 +165,13 @@ 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] : 255;
171
- const maintainGreen = maintainData ? maintainData[i + 1] : 255;
172
- const maintainBlue = maintainData ? maintainData[i + 2] : 255;
168
+ const maintainRed = maintainData ? maintainData[i] : 1;
169
+ const maintainGreen = maintainData ? maintainData[i + 1] : 0;
170
+ const maintainBlue = maintainData ? maintainData[i + 2] : 0;
173
171
  const maintainAlpha = maintainData ? maintainData[i + 3] : 255;
174
- const newRed = newData ? newData[i] : 255;
175
- const newGreen = newData ? newData[i + 1] : 255;
176
- const newBlue = newData ? newData[i + 2] : 255;
172
+ const newRed = newData ? newData[i] : 1;
173
+ const newGreen = newData ? newData[i + 1] : 0;
174
+ const newBlue = newData ? newData[i + 2] : 0;
177
175
  const newAlpha = newData ? newData[i + 3] : 255;
178
176
  combinedData[i] = channelToUpdate === 'R' ? newRed : maintainRed;
179
177
  combinedData[i + 1] = channelToUpdate === 'G' ? newGreen : maintainGreen;
@@ -397,6 +395,8 @@ export const updateMaterial = inboundData => {
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,
@@ -438,6 +438,8 @@ export const updateMaterial = inboundData => {
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -39,9 +39,9 @@ const removeChannelFromTexture = (image, channel) => {
39
39
  const combinedData = combinedImageData.data;
40
40
 
41
41
  for (let i = 0; i < combinedData.length; i += 4) {
42
- combinedData[i] = channel === 'R' ? 255 : imageData[i];
43
- combinedData[i + 1] = channel === 'G' ? 255 : imageData[i + 1];
44
- 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];
45
45
  combinedData[i + 3] = channel === 'A' ? 255 : imageData[i + 3];
46
46
  }
47
47
 
@@ -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,14 +211,14 @@ 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] : 255;
216
- const maintainGreen = maintainData ? maintainData[i + 1] : 255;
217
- const maintainBlue = maintainData ? maintainData[i + 2] : 255;
214
+ const maintainRed = maintainData ? maintainData[i] : 1;
215
+ const maintainGreen = maintainData ? maintainData[i + 1] : 0;
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] : 255;
221
- const newGreen = newData ? newData[i + 1] : 255;
222
- const newBlue = newData ? newData[i + 2] : 255;
219
+ const newRed = newData ? newData[i] : 1;
220
+ const newGreen = newData ? newData[i + 1] : 0;
221
+ const newBlue = newData ? newData[i + 2] : 0;
223
222
  const newAlpha = newData ? newData[i + 3] : 255;
224
223
 
225
224
  combinedData[i] = channelToUpdate === 'R' ? newRed : maintainRed;
@@ -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
@@ -455,6 +453,8 @@ export const updateMaterial = inboundData => {
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 });
@@ -495,6 +495,8 @@ export const updateMaterial = inboundData => {
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 });
@@ -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}