MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / loadPreviewModel

Function loadPreviewModel

preview.js:449–580  ·  view source on GitHub ↗
(filePath, loadToken)

Source from the content-addressed store, hash-verified

447 function hasColorData(object) {
448 let hasColor = false;
449 object.traverse((child) => {
450 if (!child.isMesh) return;
451 const geometry = child.geometry;
452 if (geometry && geometry.attributes && geometry.attributes.color) {
453 hasColor = true;
454 }
455 const material = child.material;
456 const materials = Array.isArray(material) ? material : [material];
457 for (const mat of materials) {
458 if (!mat) continue;
459 if (mat.map || mat.vertexColors) {
460 hasColor = true;
461 }
462 if (mat.color) {
463 const { r, g, b } = mat.color;
464 if (r > 0.05 || g > 0.05 || b > 0.05) {
465 hasColor = true;
466 }
467 }
468 }
469 });
470 return hasColor;
471 }
472
473 function applyDefaultMetalMaterial(object) {
474 const material = new THREE.MeshStandardMaterial({
475 color: 0x4a4a4a,
476 metalness: 0.85,
477 roughness: 0.35,
478 flatShading: false
479 });
480
481 object.traverse((child) => {
482 if (!child.isMesh) return;
483 if (Array.isArray(child.material)) {
484 child.material = child.material.map(() => material.clone());
485 } else {
486 child.material = material.clone();
487 }
488 });
489 }
490
491 function ensureLitMaterials(object) {
492 object.traverse((child) => {
493 if (!child.isMesh) return;
494 const materials = Array.isArray(child.material) ? child.material : [child.material];
495 materials.forEach((mat, index) => {
496 if (!mat) return;
497 const hasTexture = !!mat.map;
498 const usesVertexColors = !!mat.vertexColors;
499 const color = mat.color ? mat.color.clone() : new THREE.Color(0xffffff);
500 if (hasTexture || usesVertexColors) {
501 color.set(0xffffff);
502 }
503 if (mat.isMeshBasicMaterial) {
504 const converted = new THREE.MeshStandardMaterial({
505 color,
506 map: mat.map || null,

Callers 1

openPreviewFunction · 0.85

Calls 7

validateSTLBufferFunction · 0.85
centerAndScaleModelFunction · 0.85
updateModelDimensionsFunction · 0.85
hasColorDataFunction · 0.85
ensureLitMaterialsFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected