three-zoo 0.9.0 → 0.9.2

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,7 +1,9 @@
1
- export * from "./DualFovCamera";
2
- export * from "./SceneTraversal";
3
- export * from "./SkinnedMeshBaker";
4
- export * from "./StandardToBasicConverter";
5
- export * from "./StandardToLambertConverter";
6
- export * from "./StandardToPhongConverter";
7
- export * from "./Sun";
1
+ export { DualFovCamera } from "./DualFovCamera";
2
+ export { SceneTraversal } from "./SceneTraversal";
3
+ export { SkinnedMeshBaker } from "./SkinnedMeshBaker";
4
+ export { StandardToBasicConverter } from "./StandardToBasicConverter";
5
+ export { StandardToLambertConverter } from "./StandardToLambertConverter";
6
+ export { StandardToPhongConverter } from "./StandardToPhongConverter";
7
+ export { StandardToPhysicalConverter } from "./StandardToPhysicalConverter";
8
+ export { StandardToToonConverter } from "./StandardToToonConverter";
9
+ export { Sun } from "./Sun";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { PerspectiveCamera, MathUtils, Vector3, Mesh, BufferAttribute, AnimationMixer, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, Color, DirectionalLight, Box3, Spherical, RGBAFormat } from 'three';
1
+ import { PerspectiveCamera, MathUtils, Vector3, Mesh, BufferAttribute, AnimationMixer, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, Color, MeshPhysicalMaterial, MeshToonMaterial, DirectionalLight, Box3, Spherical, RGBAFormat } from 'three';
2
2
 
3
3
  /** Default horizontal field of view in degrees */
4
4
  const DEFAULT_HORIZONTAL_FOV = 90;
@@ -1022,6 +1022,345 @@ class StandardToPhongConverter {
1022
1022
  }
1023
1023
  }
1024
1024
 
1025
+ /**
1026
+ * Converts MeshStandardMaterial to MeshPhysicalMaterial.
1027
+ *
1028
+ * MeshPhysicalMaterial extends MeshStandardMaterial with additional
1029
+ * physically-based properties like clearcoat, sheen, and transmission.
1030
+ * This converter copies all Standard properties and allows setting
1031
+ * Physical-specific defaults.
1032
+ */
1033
+ class StandardToPhysicalConverter {
1034
+ /**
1035
+ * Converts MeshStandardMaterial to MeshPhysicalMaterial.
1036
+ *
1037
+ * @param material - Source material to convert
1038
+ * @param options - Conversion options
1039
+ * @returns New MeshPhysicalMaterial with mapped properties
1040
+ */
1041
+ static convert(material, options = {}) {
1042
+ const config = {
1043
+ preserveName: true,
1044
+ copyUserData: true,
1045
+ disposeOriginal: false,
1046
+ clearcoat: 0,
1047
+ clearcoatRoughness: 0,
1048
+ sheen: 0,
1049
+ transmission: 0,
1050
+ ior: 1.5,
1051
+ ...options,
1052
+ };
1053
+ // Create new Physical material
1054
+ const physicalMaterial = new MeshPhysicalMaterial();
1055
+ // Copy basic material properties
1056
+ this.copyBasicProperties(material, physicalMaterial, config);
1057
+ // Copy Standard material properties (Physical extends Standard)
1058
+ this.copyStandardProperties(material, physicalMaterial);
1059
+ // Handle texture maps
1060
+ this.convertTextureMaps(material, physicalMaterial);
1061
+ // Handle transparency and alpha
1062
+ this.convertTransparencyProperties(material, physicalMaterial);
1063
+ // Apply Physical-specific properties from config
1064
+ this.applyPhysicalProperties(physicalMaterial, config);
1065
+ // Cleanup if requested
1066
+ if (config.disposeOriginal) {
1067
+ material.dispose();
1068
+ }
1069
+ physicalMaterial.needsUpdate = true;
1070
+ return physicalMaterial;
1071
+ }
1072
+ /**
1073
+ * Copies basic material properties.
1074
+ *
1075
+ * @param source - Source material
1076
+ * @param target - Target material
1077
+ * @param config - Configuration options
1078
+ * @internal
1079
+ */
1080
+ static copyBasicProperties(source, target, config) {
1081
+ if (config.preserveName) {
1082
+ target.name = source.name;
1083
+ }
1084
+ target.side = source.side;
1085
+ target.visible = source.visible;
1086
+ target.fog = source.fog;
1087
+ target.wireframe = source.wireframe;
1088
+ target.wireframeLinewidth = source.wireframeLinewidth;
1089
+ target.vertexColors = source.vertexColors;
1090
+ target.flatShading = source.flatShading;
1091
+ if (config.copyUserData) {
1092
+ target.userData = { ...source.userData };
1093
+ }
1094
+ }
1095
+ /**
1096
+ * Copies MeshStandardMaterial-specific properties.
1097
+ *
1098
+ * @param source - Source material
1099
+ * @param target - Target material
1100
+ * @internal
1101
+ */
1102
+ static copyStandardProperties(source, target) {
1103
+ // Color properties
1104
+ target.color = source.color.clone();
1105
+ target.emissive = source.emissive.clone();
1106
+ target.emissiveIntensity = source.emissiveIntensity;
1107
+ // PBR properties
1108
+ target.metalness = source.metalness;
1109
+ target.roughness = source.roughness;
1110
+ // Environment map properties
1111
+ target.envMapIntensity = source.envMapIntensity;
1112
+ }
1113
+ /**
1114
+ * Converts texture properties from Standard to Physical material.
1115
+ *
1116
+ * @param source - Source material
1117
+ * @param target - Target material
1118
+ * @internal
1119
+ */
1120
+ static convertTextureMaps(source, target) {
1121
+ // Diffuse/Albedo map
1122
+ if (source.map) {
1123
+ target.map = source.map;
1124
+ }
1125
+ // Emissive map
1126
+ if (source.emissiveMap) {
1127
+ target.emissiveMap = source.emissiveMap;
1128
+ }
1129
+ // Normal map
1130
+ if (source.normalMap) {
1131
+ target.normalMap = source.normalMap;
1132
+ target.normalMapType = source.normalMapType;
1133
+ target.normalScale = source.normalScale.clone();
1134
+ }
1135
+ // Bump map
1136
+ if (source.bumpMap) {
1137
+ target.bumpMap = source.bumpMap;
1138
+ target.bumpScale = source.bumpScale;
1139
+ }
1140
+ // Displacement map
1141
+ if (source.displacementMap) {
1142
+ target.displacementMap = source.displacementMap;
1143
+ target.displacementScale = source.displacementScale;
1144
+ target.displacementBias = source.displacementBias;
1145
+ }
1146
+ // Roughness map
1147
+ if (source.roughnessMap) {
1148
+ target.roughnessMap = source.roughnessMap;
1149
+ }
1150
+ // Metalness map
1151
+ if (source.metalnessMap) {
1152
+ target.metalnessMap = source.metalnessMap;
1153
+ }
1154
+ // Light map
1155
+ if (source.lightMap) {
1156
+ target.lightMap = source.lightMap;
1157
+ target.lightMapIntensity = source.lightMapIntensity;
1158
+ }
1159
+ // AO map
1160
+ if (source.aoMap) {
1161
+ target.aoMap = source.aoMap;
1162
+ target.aoMapIntensity = source.aoMapIntensity;
1163
+ }
1164
+ // Environment map
1165
+ if (source.envMap) {
1166
+ target.envMap = source.envMap;
1167
+ }
1168
+ // Alpha map
1169
+ if (source.alphaMap) {
1170
+ target.alphaMap = source.alphaMap;
1171
+ }
1172
+ }
1173
+ /**
1174
+ * Converts transparency and rendering properties.
1175
+ *
1176
+ * @param source - Source material
1177
+ * @param target - Target material
1178
+ * @internal
1179
+ */
1180
+ static convertTransparencyProperties(source, target) {
1181
+ target.transparent = source.transparent;
1182
+ target.opacity = source.opacity;
1183
+ target.alphaTest = source.alphaTest;
1184
+ target.depthTest = source.depthTest;
1185
+ target.depthWrite = source.depthWrite;
1186
+ target.blending = source.blending;
1187
+ }
1188
+ /**
1189
+ * Applies Physical-specific properties from configuration.
1190
+ *
1191
+ * @param target - Target material
1192
+ * @param config - Configuration options
1193
+ * @internal
1194
+ */
1195
+ static applyPhysicalProperties(target, config) {
1196
+ target.clearcoat = config.clearcoat;
1197
+ target.clearcoatRoughness = config.clearcoatRoughness;
1198
+ target.sheen = config.sheen;
1199
+ target.transmission = config.transmission;
1200
+ target.ior = config.ior;
1201
+ }
1202
+ }
1203
+
1204
+ /**
1205
+ * Converts MeshStandardMaterial to MeshToonMaterial.
1206
+ *
1207
+ * MeshToonMaterial provides a cel-shaded/cartoon appearance with
1208
+ * discrete lighting steps. This converter maps Standard material
1209
+ * properties to Toon material, preserving color and texture information
1210
+ * while applying toon shading characteristics.
1211
+ *
1212
+ * Note: Some PBR properties (metalness, roughness) are not supported
1213
+ * by MeshToonMaterial and will be ignored.
1214
+ */
1215
+ class StandardToToonConverter {
1216
+ /**
1217
+ * Converts MeshStandardMaterial to MeshToonMaterial.
1218
+ *
1219
+ * @param material - Source material to convert
1220
+ * @param options - Conversion options
1221
+ * @returns New MeshToonMaterial with mapped properties
1222
+ */
1223
+ static convert(material, options = {}) {
1224
+ const config = {
1225
+ preserveName: true,
1226
+ copyUserData: true,
1227
+ disposeOriginal: false,
1228
+ gradientMap: null,
1229
+ ...options,
1230
+ };
1231
+ // Create new Toon material
1232
+ const toonMaterial = new MeshToonMaterial();
1233
+ // Copy basic material properties
1234
+ this.copyBasicProperties(material, toonMaterial, config);
1235
+ // Handle color properties
1236
+ this.convertColorProperties(material, toonMaterial);
1237
+ // Handle texture maps
1238
+ this.convertTextureMaps(material, toonMaterial);
1239
+ // Handle transparency and alpha
1240
+ this.convertTransparencyProperties(material, toonMaterial);
1241
+ // Apply toon-specific properties
1242
+ this.applyToonProperties(toonMaterial, config);
1243
+ // Cleanup if requested
1244
+ if (config.disposeOriginal) {
1245
+ material.dispose();
1246
+ }
1247
+ toonMaterial.needsUpdate = true;
1248
+ return toonMaterial;
1249
+ }
1250
+ /**
1251
+ * Copies basic material properties.
1252
+ *
1253
+ * @param source - Source material
1254
+ * @param target - Target material
1255
+ * @param config - Configuration options
1256
+ * @internal
1257
+ */
1258
+ static copyBasicProperties(source, target, config) {
1259
+ if (config.preserveName) {
1260
+ target.name = source.name;
1261
+ }
1262
+ target.side = source.side;
1263
+ target.visible = source.visible;
1264
+ target.fog = source.fog;
1265
+ target.wireframe = source.wireframe;
1266
+ target.wireframeLinewidth = source.wireframeLinewidth;
1267
+ target.vertexColors = source.vertexColors;
1268
+ if (config.copyUserData) {
1269
+ target.userData = { ...source.userData };
1270
+ }
1271
+ }
1272
+ /**
1273
+ * Converts color properties from Standard to Toon material.
1274
+ *
1275
+ * @param source - Source material
1276
+ * @param target - Target material
1277
+ * @internal
1278
+ */
1279
+ static convertColorProperties(source, target) {
1280
+ target.color = source.color.clone();
1281
+ target.emissive = source.emissive.clone();
1282
+ target.emissiveIntensity = source.emissiveIntensity;
1283
+ }
1284
+ /**
1285
+ * Converts texture properties from Standard to Toon material.
1286
+ *
1287
+ * Note: MeshToonMaterial does not support roughnessMap, metalnessMap,
1288
+ * or envMap. These properties are intentionally skipped.
1289
+ *
1290
+ * @param source - Source material
1291
+ * @param target - Target material
1292
+ * @internal
1293
+ */
1294
+ static convertTextureMaps(source, target) {
1295
+ // Diffuse/Albedo map
1296
+ if (source.map) {
1297
+ target.map = source.map;
1298
+ }
1299
+ // Emissive map
1300
+ if (source.emissiveMap) {
1301
+ target.emissiveMap = source.emissiveMap;
1302
+ }
1303
+ // Normal map
1304
+ if (source.normalMap) {
1305
+ target.normalMap = source.normalMap;
1306
+ target.normalMapType = source.normalMapType;
1307
+ target.normalScale = source.normalScale.clone();
1308
+ }
1309
+ // Bump map
1310
+ if (source.bumpMap) {
1311
+ target.bumpMap = source.bumpMap;
1312
+ target.bumpScale = source.bumpScale;
1313
+ }
1314
+ // Displacement map
1315
+ if (source.displacementMap) {
1316
+ target.displacementMap = source.displacementMap;
1317
+ target.displacementScale = source.displacementScale;
1318
+ target.displacementBias = source.displacementBias;
1319
+ }
1320
+ // Light map
1321
+ if (source.lightMap) {
1322
+ target.lightMap = source.lightMap;
1323
+ target.lightMapIntensity = source.lightMapIntensity;
1324
+ }
1325
+ // AO map
1326
+ if (source.aoMap) {
1327
+ target.aoMap = source.aoMap;
1328
+ target.aoMapIntensity = source.aoMapIntensity;
1329
+ }
1330
+ // Alpha map
1331
+ if (source.alphaMap) {
1332
+ target.alphaMap = source.alphaMap;
1333
+ }
1334
+ }
1335
+ /**
1336
+ * Converts transparency and rendering properties.
1337
+ *
1338
+ * @param source - Source material
1339
+ * @param target - Target material
1340
+ * @internal
1341
+ */
1342
+ static convertTransparencyProperties(source, target) {
1343
+ target.transparent = source.transparent;
1344
+ target.opacity = source.opacity;
1345
+ target.alphaTest = source.alphaTest;
1346
+ target.depthTest = source.depthTest;
1347
+ target.depthWrite = source.depthWrite;
1348
+ target.blending = source.blending;
1349
+ }
1350
+ /**
1351
+ * Applies Toon-specific properties from configuration.
1352
+ *
1353
+ * @param target - Target material
1354
+ * @param config - Configuration options
1355
+ * @internal
1356
+ */
1357
+ static applyToonProperties(target, config) {
1358
+ if (config.gradientMap) {
1359
+ target.gradientMap = config.gradientMap;
1360
+ }
1361
+ }
1362
+ }
1363
+
1025
1364
  /** Number of color channels in RGBA format */
1026
1365
  const RGBA_CHANNEL_COUNT = 4;
1027
1366
  /** Number of color channels in RGB format */
@@ -1159,5 +1498,5 @@ class Sun extends DirectionalLight {
1159
1498
  }
1160
1499
  }
1161
1500
 
1162
- export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, Sun };
1501
+ export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
1163
1502
  //# sourceMappingURL=index.js.map