iOS Simulator'da çalışacak bir doku haritasına sahip basit bir dörtlü görüntülemeye çalışırken sorun yaşıyorum. Burada benzer şeylerle uğraşan diğer soruları okudum ve sıkışıp kaldım. Çıktı aşağıdaki gibidir:iOS Özel Geometri SceneKit'te
// v1 +----+ v0
// | |
// v2 +----+ v3
SCNVector3 vertices[] = { SCNVector3Make( 5.0, 5.0, 0.0),
SCNVector3Make(-5.0, 5.0, 0.0),
SCNVector3Make(-5.0, -5.0, 0.0),
SCNVector3Make( 5.0, -5.0, 0.0)
};
SCNVector3 normals[] = { SCNVector3Make(0.0f, 0.0f, 1.0),
SCNVector3Make(0.0f, 0.0f, 1.0),
SCNVector3Make(0.0f, 0.0f, 1.0),
SCNVector3Make(0.0f, 0.0f, 1.0)
};
CGPoint textureCoordinates[] = { CGPointMake(1.0, 1.0),
CGPointMake(0.0, 1.0),
CGPointMake(0.0, 0.0),
CGPointMake(1.0, 0.0)
};
NSUInteger vertexCount = 4;
NSMutableData *indicesData = [NSMutableData data];
UInt8 indices[] = { 0, 1, 2, 0, 2, 3};
[indicesData appendBytes:indices length:sizeof(UInt8)*6];
SCNGeometryElement *indicesElement = [SCNGeometryElement geometryElementWithData:indicesData
primitiveType:SCNGeometryPrimitiveTypeTriangles
primitiveCount:2
bytesPerIndex:sizeof(UInt8)];
NSMutableData *vertexData = [NSMutableData dataWithBytes:vertices length:vertexCount * sizeof(SCNVector3)];
SCNGeometrySource *verticesSource = [SCNGeometrySource geometrySourceWithData:vertexData
semantic:SCNGeometrySourceSemanticVertex
vectorCount:vertexCount
floatComponents:YES
componentsPerVector:3
bytesPerComponent:sizeof(float)
dataOffset:0
dataStride:sizeof(SCNVector3)];
NSMutableData *normalData = [NSMutableData dataWithBytes:normals length:vertexCount * sizeof(SCNVector3)];
SCNGeometrySource *normalsSource = [SCNGeometrySource geometrySourceWithData:normalData
semantic:SCNGeometrySourceSemanticNormal
vectorCount:vertexCount
floatComponents:YES
componentsPerVector:3
bytesPerComponent:sizeof(float)
dataOffset:0
dataStride:sizeof(SCNVector3)];
NSMutableData *textureData = [NSMutableData dataWithBytes:textureCoordinates length:vertexCount * sizeof(CGPoint)];
SCNGeometrySource *textureSource = [SCNGeometrySource geometrySourceWithData:textureData
semantic:SCNGeometrySourceSemanticTexcoord
vectorCount:vertexCount
floatComponents:YES
componentsPerVector:2
bytesPerComponent:sizeof(float)
dataOffset:0
dataStride:sizeof(CGPoint)];
SCNGeometry *geometry = [SCNGeometry geometryWithSources:@[verticesSource, normalsSource, textureSource]
elements:@[indicesElement]];
SCNMaterial *material = [SCNMaterial material];
//material.diffuse.contents = [UIColor redColor];
material.diffuse.contents = [UIImage imageNamed:@"diffuse.jpg"];
material.diffuse.wrapS = SCNWrapModeRepeat;
material.diffuse.wrapT = SCNWrapModeRepeat;
material.diffuse.contentsTransform = SCNMatrix4MakeScale(1.0f, 1.0f, 1.0f);
material.doubleSided = YES;
material.normal.wrapS = SCNWrapModeRepeat;
material.normal.wrapT = SCNWrapModeRepeat;
// material.litPerPixel = YES;
geometry.materials = @[material];
[Düzenle] denedim çok farklı şeyler:
Benim kod şudur:
doku şudur Bu kodla ve hiçbir şey işe yaramıyor gibi görünüyor. Henüz iOS'ta çalışan Objective-C'de çalışan bir örnek göremiyorum. Material.diffuse.wrapS için herhangi bir değişiklik yoktur.
OpenGL'de bu tür bir şeyi daha önce hiç sorun olmadan yaptım, ancak bu koda günlerce bakıyordum ve hatamı göremiyorum. Herhangi bir yardım gerçekten takdir edilecektir. Paul-Jan Bu yanıt bana yol doğru yolda, beni koymak @
64 bit iOS üzerinde * a * çift bir CGFloat değil midir? TextureSource öğesinin "byesPerComponent" değeri için * sizeof (float) * değerini belirtin. –
Maalesef hiç farketmedik. Ancak çok hızlı cevap için teşekkürler. – Brett
@ Paul-Jan Tavsiyemi denediğimde cevabımı aşağıya bakın, sadece textureSource içinde değiştirdim ve textureData içinde değil. Tekrar baktı ve her iki yerde de değişti ve işe yaradı. Bunu bir cevap olarak yazmak isterseniz, bunu kabul edeceğim, aksi takdirde kendi cevabımı kabul edeceğim. – Brett