three-zoo 0.11.2 → 0.11.3

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { DualFovCamera } from "./DualFovCamera";
2
+ export { BasicToPhysicalConverter } from "./materialConverters/BasicToPhysicalConverter";
2
3
  export { StandardToBasicConverter } from "./materialConverters/StandardToBasicConverter";
3
4
  export { StandardToLambertConverter } from "./materialConverters/StandardToLambertConverter";
4
5
  export { StandardToPhongConverter } from "./materialConverters/StandardToPhongConverter";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { PerspectiveCamera, MathUtils, Vector3, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, Color, MeshPhysicalMaterial, MeshToonMaterial, Mesh, BufferAttribute, AnimationMixer, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical } from 'three';
1
+ import { PerspectiveCamera, MathUtils, Vector3, MeshPhysicalMaterial, Color, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, Mesh, BufferAttribute, AnimationMixer, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical } from 'three';
2
2
 
3
3
  /** Default horizontal field of view in degrees */
4
4
  const DEFAULT_HORIZONTAL_FOV = 90;
@@ -242,6 +242,111 @@ class DualFovCamera extends PerspectiveCamera {
242
242
  }
243
243
  }
244
244
 
245
+ class BasicToPhysicalConverter {
246
+ static convert(material, options = {}) {
247
+ const config = Object.assign({ preserveName: true, copyUserData: true, disposeOriginal: false }, options);
248
+ const physicalMaterial = new MeshPhysicalMaterial();
249
+ this.copyBasicProperties(material, physicalMaterial, config);
250
+ this.convertColorAndPBRProperties(material, physicalMaterial, config);
251
+ this.convertTextureMaps(material, physicalMaterial);
252
+ this.convertTransparencyProperties(material, physicalMaterial);
253
+ this.applyPhysicalProperties(physicalMaterial, config);
254
+ if (config.disposeOriginal) {
255
+ material.dispose();
256
+ }
257
+ physicalMaterial.needsUpdate = true;
258
+ return physicalMaterial;
259
+ }
260
+ static copyBasicProperties(source, target, config) {
261
+ if (config.preserveName) {
262
+ target.name = source.name;
263
+ }
264
+ target.side = source.side;
265
+ target.visible = source.visible;
266
+ target.fog = source.fog;
267
+ target.wireframe = source.wireframe;
268
+ target.wireframeLinewidth = source.wireframeLinewidth;
269
+ target.wireframeLinecap = source.wireframeLinecap;
270
+ target.wireframeLinejoin = source.wireframeLinejoin;
271
+ target.vertexColors = source.vertexColors;
272
+ if (config.copyUserData && source.userData) {
273
+ target.userData = Object.assign({}, source.userData);
274
+ }
275
+ }
276
+ static convertColorAndPBRProperties(source, target, config) {
277
+ if (source.color) {
278
+ target.color = source.color.clone();
279
+ }
280
+ if (config.emissive !== undefined) {
281
+ if (config.emissive instanceof Color) {
282
+ target.emissive.copy(config.emissive);
283
+ }
284
+ else {
285
+ target.emissive.set(config.emissive);
286
+ }
287
+ }
288
+ if (config.emissiveIntensity !== undefined) {
289
+ target.emissiveIntensity = config.emissiveIntensity;
290
+ }
291
+ if (config.metalness !== undefined) {
292
+ target.metalness = config.metalness;
293
+ }
294
+ if (config.roughness !== undefined) {
295
+ target.roughness = config.roughness;
296
+ }
297
+ }
298
+ static convertTextureMaps(source, target) {
299
+ if (source.map) {
300
+ target.map = source.map;
301
+ }
302
+ if (source.alphaMap) {
303
+ target.alphaMap = source.alphaMap;
304
+ }
305
+ if (source.lightMap) {
306
+ target.lightMap = source.lightMap;
307
+ target.lightMapIntensity = source.lightMapIntensity;
308
+ }
309
+ if (source.aoMap) {
310
+ target.aoMap = source.aoMap;
311
+ target.aoMapIntensity = source.aoMapIntensity;
312
+ }
313
+ if (source.envMap) {
314
+ target.envMap = source.envMap;
315
+ }
316
+ }
317
+ static convertTransparencyProperties(source, target) {
318
+ target.transparent = source.transparent;
319
+ target.opacity = source.opacity;
320
+ target.alphaTest = source.alphaTest;
321
+ target.depthTest = source.depthTest;
322
+ target.depthWrite = source.depthWrite;
323
+ target.blending = source.blending;
324
+ target.blendSrc = source.blendSrc;
325
+ target.blendDst = source.blendDst;
326
+ target.blendEquation = source.blendEquation;
327
+ target.blendSrcAlpha = source.blendSrcAlpha;
328
+ target.blendDstAlpha = source.blendDstAlpha;
329
+ target.blendEquationAlpha = source.blendEquationAlpha;
330
+ }
331
+ static applyPhysicalProperties(target, config) {
332
+ if (config.clearcoat !== undefined) {
333
+ target.clearcoat = config.clearcoat;
334
+ }
335
+ if (config.clearcoatRoughness !== undefined) {
336
+ target.clearcoatRoughness = config.clearcoatRoughness;
337
+ }
338
+ if (config.sheen !== undefined) {
339
+ target.sheen = config.sheen;
340
+ }
341
+ if (config.transmission !== undefined) {
342
+ target.transmission = config.transmission;
343
+ }
344
+ if (config.ior !== undefined) {
345
+ target.ior = config.ior;
346
+ }
347
+ }
348
+ }
349
+
245
350
  /** Factor for metalness brightness adjustment */
246
351
  const METALNESS_BRIGHTNESS_FACTOR = 0.3;
247
352
  /** Factor for emissive color contribution when combining with base color */
@@ -1660,5 +1765,5 @@ class Sun extends DirectionalLight {
1660
1765
  }
1661
1766
  }
1662
1767
 
1663
- export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
1768
+ export { BasicToPhysicalConverter, DualFovCamera, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
1664
1769
  //# sourceMappingURL=index.js.map