1

通过使用“geometrySourceWithData”代码,球体的一半,如:

NSData *indicesData = [NSData dataWithBytes:indices
                                     length:sizeof(indices)*indexCount];
SCNGeometryElement *indicesElement = [SCNGeometryElement
                                      geometryElementWithData:indicesData
                                      primitiveType:SCNGeometryPrimitiveTypeTriangleStrip
                                      primitiveCount:indexCount
                                      bytesPerIndex:sizeof(int)];

NSMutableData *vertexData = [NSMutableData 
                             dataWithBytes:vertices 
                             length:pointCount * sizeof(SCNVector3)];

SCNGeometrySource *verticesSource = 
[SCNGeometrySource geometrySourceWithData:vertexData
                                 semantic:SCNGeometrySourceSemanticVertex
                              vectorCount:pointCount
                          floatComponents:YES
                      componentsPerVector:3
                        bytesPerComponent:sizeof(float)
                               dataOffset:0
                               dataStride:sizeof(SCNVector3)];

NSMutableData *normalData = [NSMutableData dataWithBytes:normals
                                                  length:pointCount * sizeof(SCNVector3)];

SCNGeometrySource *normalsSource = [SCNGeometrySource 
                                    geometrySourceWithData:normalData
                                    semantic:SCNGeometrySourceSemanticNormal
                                    vectorCount:pointCount
                                    floatComponents:YES
                                    componentsPerVector:3
                                    bytesPerComponent:sizeof(float)
                                    dataOffset:0
                                    dataStride:sizeof(SCNVector3)];

NSMutableData *textureData = [NSMutableData dataWithBytes:UVs 
                                                   length:pointCount * sizeof(float)*2.0];

SCNGeometrySource *textureSource = [SCNGeometrySource 
                                    geometrySourceWithData:textureData
                                    semantic:SCNGeometrySourceSemanticTexcoord
                                    vectorCount:pointCount
                                    floatComponents:YES
                                    componentsPerVector:2
                                    bytesPerComponent:sizeof(float)
                                    dataOffset:0
                                    dataStride:sizeof(float)*2.0];
SCNGeometry *geometry = [SCNGeometry 
                         geometryWithSources:@[verticesSource, normalsSource, textureSource]

                         elements:@[indicesElement]];


SCNMaterial *blueMaterial = [SCNMaterial material];
//  material.diffuse.contents = [UIColor redColor];
blueMaterial.diffuse.contents = image;
blueMaterial.diffuse.wrapS = SCNWrapModeRepeat;
blueMaterial.diffuse.wrapT = SCNWrapModeRepeat;
blueMaterial.diffuse.contentsTransform = SCNMatrix4MakeScale( 1.0f, 1.0f, 1.0f);
blueMaterial.doubleSided = YES;

NSMutableArray *array_ = [NSMutableArray array];

[array_ addObject:blueMaterial];

geometry.materials = array_;

SCNNode *geometryNode = [SCNNode nodeWithGeometry:geometry];

在此处输入图像描述

但是中间有一个大黑点。

在此处输入图像描述

所有球体点都像这张图片:

在此处输入图像描述

或者我尝试使用 SYSTEM sphere: 并且喜欢:它比我创建更好(自定义球体)

在此处输入图像描述

---------------------更新001

sphere_.segmentCount=100;
sphere_.firstMaterial.doubleSided = NO;
sphere_.firstMaterial.cullMode =SCNCullModeFront;

[sphere_ setGeodesic:NO];

设置为不喜欢:

在此处输入图像描述

设置为 YES LIKE:哦,天哪!!!

[sphere_ setGeodesic:YES];

在此处输入图像描述

- - - - - - - - - - - - - - - - - - - - - - - - -更新20170116

原图:半个球体;

在此处输入图像描述

4

0 回答 0