盒子由六个不同的元素组成(每边一个)。您可能还注意到,几何对象具有第一种材料的一个属性,以及一组材料的属性。
具有多个元素和多种材质的对象将为每个元素选择材质(和包裹)的增量。
例如 4 个元素和 1 个材料
Element 1 2 3 4
Material 1 1 1 1
或 4 种元素和 2 种材料
Element 1 2 3 4
Material 1 2 1 2 // note that they are repeating
例如 4 种元素和 7 种材料
Element 1 2 3 4
Material 1 2 3 4 // (5, 6, 7) is unused
在盒子的情况下,这意味着您可以使用一组六种材料在盒子的每一侧都有一个独特的材料。我的Scene Kit 书(在 Objective-C 中)的其中一章的示例代码中有一个示例:
// Each side of the box has its own color
// --------------------------------------
// All have the same diffuse and ambient colors to show the
// effect of the ambient light, even with these materials.
SCNMaterial *greenMaterial = [SCNMaterial material];
greenMaterial.diffuse.contents = [NSColor greenColor];
greenMaterial.locksAmbientWithDiffuse = YES;
SCNMaterial *redMaterial = [SCNMaterial material];
redMaterial.diffuse.contents = [NSColor redColor];
redMaterial.locksAmbientWithDiffuse = YES;
SCNMaterial *blueMaterial = [SCNMaterial material];
blueMaterial.diffuse.contents = [NSColor blueColor];
blueMaterial.locksAmbientWithDiffuse = YES;
SCNMaterial *yellowMaterial = [SCNMaterial material];
yellowMaterial.diffuse.contents = [NSColor yellowColor];
yellowMaterial.locksAmbientWithDiffuse = YES;
SCNMaterial *purpleMaterial = [SCNMaterial material];
purpleMaterial.diffuse.contents = [NSColor purpleColor];
purpleMaterial.locksAmbientWithDiffuse = YES;
SCNMaterial *magentaMaterial = [SCNMaterial material];
magentaMaterial.diffuse.contents = [NSColor magentaColor];
magentaMaterial.locksAmbientWithDiffuse = YES;
box.materials = @[greenMaterial, redMaterial, blueMaterial,
yellowMaterial, purpleMaterial, magentaMaterial];