Configure Dual Materials for Fragments
mainFragments in three-pinata support two materials: one for the original outer surface and one for the newly created internal fracture faces.
Recommended Approach: Pass both materials to the DestructibleMesh constructor. The library will automatically assign them to the fragments.
- Group 0 (materialIndex 0): Original outer surface faces.
- Group 1 (materialIndex 1): Internal fracture faces.
const outerMaterial = new THREE.MeshStandardMaterial({ color: 0xff6644 });
const innerMaterial = new THREE.MeshStandardMaterial({ color: 0xdddddd });
const mesh = new DestructibleMesh(geometry, outerMaterial, innerMaterial);
const fragments = mesh.fracture(options, (fragment) => {
scene.add(fragment);
});Manual Approach: If you only pass one material to the constructor, you can manually assign the material array in the fracture callback.
const mesh = new DestructibleMesh(geometry, outerMaterial);
const fragments = mesh.fracture(options, (fragment) => {
fragment.material = [outerMaterial, innerMaterial];
scene.add(fragment);
});// Recommended approach
const outerMaterial = new THREE.MeshStandardMaterial({ color: 0xff6644 });
const innerMaterial = new THREE.MeshStandardMaterial({ color: 0xdddddd });
// Materials are automatically inherited by fragments
const mesh = new DestructibleMesh(geometry, outerMaterial, innerMaterial);
const fragments = mesh.fracture(options, (fragment) => {
// Material array [outer, inner] is already set automatically
scene.add(fragment);
});