SCNGeometry.Create Метод

Определение

Перегрузки

Create()

Создает новый элемент geometry.

Create(SCNGeometrySource[], SCNGeometryElement[])

Создает новый объект geometry из указанных массивов sources и elements.

Create()

Создает новый элемент geometry.

[Foundation.Export("geometry")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 9, ObjCRuntime.PlatformArchitecture.All, null)]
public static SceneKit.SCNGeometry Create ();
static member Create : unit -> SceneKit.SCNGeometry

Возвращаемое значение

Атрибуты

Применяется к

Create(SCNGeometrySource[], SCNGeometryElement[])

Создает новый объект geometry из указанных массивов sources и elements.

[Foundation.Export("geometryWithSources:elements:")]
public static SceneKit.SCNGeometry Create (SceneKit.SCNGeometrySource[] sources, SceneKit.SCNGeometryElement[] elements);
static member Create : SceneKit.SCNGeometrySource[] * SceneKit.SCNGeometryElement[] -> SceneKit.SCNGeometry

Параметры

sources
SCNGeometrySource[]

Массив объектов SCNGeometrySource.

elements
SCNGeometryElement[]

Массив объектов SCNGeometryElement.

Этот параметр может иметь значение null.

Возвращаемое значение

Атрибуты

Комментарии

Используется для создания пользовательской геометрии. В зависимости от потребностей разработчика число и типы массивов sources и elements могут быть весьма переменными. В следующем примере показано использование вершин, определяющих треугольники, с которыми сопоставлена одна текстура. Обратите внимание, как конкретные значения индекса в locs используются для определения indices и как порядок в влияет locs на normals и txCoords. Кроме того, обратите внимание на то, как триплеты в indices связаны с SCNGeometryPrimitiveType.Triangles.

//Lower-left
var a = new SCNVector3(-1, -1, 0);
//Upper-right
var b = new SCNVector3(1, 1, 0);

var halfX = (c.X + a.X) / 2;
var halfY = (c.Y + a.Y) / 2;
var halfZ = (c.Z + a.Z) / 2;

var b = new SCNVector3(a.X, c.Y, halfZ);
var d = new SCNVector3(c.X, a.Y, halfZ);
//Elevate the midpoint so that it's clearly a pyramid
var midPoint = new SCNVector3(halfX, halfY, halfZ + 1.0);

//The vertices of the geometry
var locs = new [] {
	a, b, c, d, midPoint
};
var locSource = SCNGeometrySource.FromVertices(locs);

//Note that this relies on the ordering of locs above
//and it defines triangles (could be triangle strips, etc.)
var indices = new [] {
	//Triangles are defined counter-clockwise!
	4, 1, 0,
	1, 4, 2,
	2, 4, 3,
	3, 4, 0
};


var idxArray = new byte[indices.Length][];
for(int i = 0; i < idxArray.Length; i++)
{
	idxArray[i] = BitConverter.GetBytes(indices[i]);
}
var idxData = NSData.FromArray(idxArray.SelectMany(id => id).ToArray());

//Note that this relies on indices defining triangles
var element = SCNGeometryElement.FromData(idxData, SCNGeometryPrimitiveType.Triangles, indices.Length / 3, sizeof(int));

//Normals are relative to geometry
var normals = new [] {
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
};;
var normSource = SCNGeometrySource.FromNormals(normals);

var txCoords = new [] {
	new CGPoint(0, 0),
	new CGPoint(0, 1),
	new CGPoint(1, 1),
	new CGPoint(1, 0),
  new CGPoint(0.5, 0.5)
};

var txCoordsSource = SCNGeometrySource.FromTextureCoordinates(txCoords);

var geometry = SCNGeometry.Create(new [] { locSource, normSource, txCoordsSource }, new [] { element });

Применяется к