本文整理匯總了C#中System.Windows.Media.Media3D.Transform3D.Transform方法的典型用法代碼示例。如果您正苦於以下問題:C# Transform3D.Transform方法的具體用法?C# Transform3D.Transform怎麽用?C# Transform3D.Transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Media.Media3D.Transform3D
的用法示例。
在下文中一共展示了Transform3D.Transform方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CalcRotationMatrix
public static Matrix3D CalcRotationMatrix(double x, double y, double z, Point3D center, Vector3D up, Vector3D look, Transform3D transform, RotationType type)
{
//Transform3DGroup trm = new Transform3DGroup();
//trm.Children.Add(transform);
Vector3D realup = transform.Transform(up);
if (type != RotationType.LockAxisY)
{
up = realup;
}
if (type != RotationType.LockAxisZ)
{
look = transform.Transform(look);
}
center = transform.Transform(center);
Vector3D axisX = Vector3D.CrossProduct(up, look);
Matrix3D matrix = new Matrix3D();
//Quaternion q = new Quaternion();
//q.
double ang = AngleBetween(realup, YAxis) + x;
if (ang >= 90)
{
x = 90 - ang;
}
matrix.RotateAt(new Quaternion(axisX, x), center);
matrix.RotateAt(new Quaternion(up, y), center);
matrix.RotateAt(new Quaternion(look, z), center);
return matrix;
}
示例2: GetTransformedPerspectiveCamera
public static PerspectiveCamera GetTransformedPerspectiveCamera(PerspectiveCamera camera, Transform3D transform)
{
return new PerspectiveCamera
{
LookDirection = transform.Transform(camera.LookDirection),
UpDirection = transform.Transform(camera.UpDirection),
FieldOfView = camera.FieldOfView,
FarPlaneDistance = camera.FarPlaneDistance,
NearPlaneDistance = camera.NearPlaneDistance,
Position = transform.Transform(camera.Position)
};
}
示例3: CalculateRotationMatrix
public static Matrix3D CalculateRotationMatrix(double x, double y, double z, Point3D center, Vector3D up, Vector3D look, Transform3D transform)
{
//Transform3DGroup trm = new Transform3DGroup();
//trm.Children.Add(transform);
up = transform.Transform(up);
look = transform.Transform(look);
center = transform.Transform(center);
Vector3D axisZ = Vector3D.CrossProduct(up, look);
Matrix3D matrix = new Matrix3D();
matrix.RotateAt(new Quaternion(axisZ, x), center);
matrix.RotateAt(new Quaternion(up, y), center);
matrix.RotateAt(new Quaternion(look, z), center);
return matrix;
}
示例4: AlphaSort
// http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Components-PostAttachments/00-04-01-86-12/SceneSortingHelper_2E00_cs
/// <summary>
/// Sort Modelgroups in Farthest to Closest order, to enable transparency
/// Should be applied whenever the scene is significantly re-oriented
/// </summary>
public static void AlphaSort(Point3D cameraPosition, Model3DCollection models, Transform3D worldTransform)
{
var sortedList = models.OrderBy(model => Point3D.Subtract(cameraPosition, worldTransform.Transform(model.Bounds.Location)).Length);
models.Clear();
foreach (var model in sortedList)
{
models.Add(model);
}
}
示例5: Rotate3D
public static MatrixTransform3D Rotate3D(Transform3D transform, Vector3D look, Vector3D dir, Point3D center)
{
Matrix3D m = new Matrix3D();
Vector3D realook = transform.Transform(look);
Vector3D axis = Vector3D.CrossProduct(realook, dir);
double angle = Math.Acos(Vector3D.DotProduct(realook, dir));
Quaternion q = new Quaternion(axis, angle);
m.RotateAt(q, center);
MatrixTransform3D rlt = transform as MatrixTransform3D;
return new MatrixTransform3D(Matrix3D.Multiply(rlt.Matrix, m));
}
示例6: ExportMesh
public void ExportMesh(MeshGeometry3D m, Transform3D t)
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
Dictionary<int, int> dictionary2 = new Dictionary<int, int>();
Dictionary<int, int> dictionary3 = new Dictionary<int, int>();
int num = 0;
foreach (Point3D pointd in m.Positions)
{
dictionary.Add(num++, this.vertexIndex++);
Point3D pointd2 = t.Transform(pointd);
this.writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "v {0} {1} {2}", new object[] { pointd2.X, pointd2.Y, pointd2.Z }));
}
num = 0;
foreach (Point point in m.TextureCoordinates)
{
if (!(double.IsNegativeInfinity(point.X) || double.IsPositiveInfinity(point.Y)))
{
dictionary2.Add(num++, this.textureIndex++);
this.writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "vt {0} {1}", new object[] { point.X, point.Y }));
}
else
{
num++;
}
}
num = 0;
foreach (Vector3D vectord in m.Normals)
{
if (!(double.IsNegativeInfinity(vectord.X) || double.IsPositiveInfinity(vectord.Y)))
{
dictionary3.Add(num++, this.normalIndex++);
this.writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "vn {0} {1} {2}", new object[] { vectord.X, vectord.Y, vectord.Z }));
}
else
{
num++;
}
}
for (int i = 0; i < m.TriangleIndices.Count; i += 3)
{
int num6;
int key = m.TriangleIndices[i];
int num4 = m.TriangleIndices[i + 1];
int num5 = m.TriangleIndices[i + 2];
this.writer.WriteLine("f {0}/{1}{2} {3}/{4}{5} {6}/{7}{8}", new object[] { dictionary[key], dictionary2.ContainsKey(key) ? (num6 = dictionary2[key]).ToString() : string.Empty, dictionary3.ContainsKey(key) ? ("/" + (num6 = dictionary3[key]).ToString()) : string.Empty, dictionary[num4], dictionary2.ContainsKey(num4) ? (num6 = dictionary2[num4]).ToString() : string.Empty, dictionary3.ContainsKey(num4) ? ("/" + (num6 = dictionary3[num4]).ToString()) : string.Empty, dictionary[num5], dictionary2.ContainsKey(num5) ? (num6 = dictionary2[num5]).ToString() : string.Empty, dictionary3.ContainsKey(num5) ? ("/" + (num6 = dictionary3[num5]).ToString()) : string.Empty });
}
}
示例7: GetDome
private static void GetDome(ref int pointOffset, MeshGeometry3D geometry, Point[] pointsTheta, Transform3D transform, int numSegmentsPhi, double radiusX, double radiusY, double radiusZ)
{
#region Initial calculations
// NOTE: There is one more than what the passed in
Point[] pointsPhi = new Point[numSegmentsPhi + 1];
pointsPhi[0] = new Point(1d, 0d); // along the equator
pointsPhi[numSegmentsPhi] = new Point(0d, 1d); // north pole
if (pointsPhi.Length > 2)
{
// Need to go from 0 to half pi
double halfPi = Math.PI * .5d;
double deltaPhi = halfPi / pointsPhi.Length; // there is one more point than numSegmentsPhi
for (int cntr = 1; cntr < numSegmentsPhi; cntr++)
{
double phi = deltaPhi * cntr; // phi goes from 0 to pi for a full sphere, so start halfway up
pointsPhi[cntr] = new Point(Math.Cos(phi), Math.Sin(phi));
}
}
#endregion
#region Positions/Normals
// Can't use all of the transform passed in for the normal, because translate portions will skew the normal funny
Transform3DGroup normalTransform = new Transform3DGroup();
if (transform is Transform3DGroup)
{
foreach (var subTransform in ((Transform3DGroup)transform).Children)
{
if (!(subTransform is TranslateTransform3D))
{
normalTransform.Children.Add(subTransform);
}
}
}
else if (transform is TranslateTransform3D)
{
normalTransform.Children.Add(Transform3D.Identity);
}
else
{
normalTransform.Children.Add(transform);
}
//for (int phiCntr = 0; phiCntr < numSegmentsPhi; phiCntr++) // The top point will be added after this loop
for (int phiCntr = pointsPhi.Length - 1; phiCntr > 0; phiCntr--)
{
for (int thetaCntr = 0; thetaCntr < pointsTheta.Length; thetaCntr++)
{
// Phi points are going from bottom to equator.
Point3D point = new Point3D(
radiusX * pointsTheta[thetaCntr].X * pointsPhi[phiCntr].Y,
radiusY * pointsTheta[thetaCntr].Y * pointsPhi[phiCntr].Y,
radiusZ * pointsPhi[phiCntr].X);
geometry.Positions.Add(transform.Transform(point));
//TODO: For a standalone dome, the bottom rings will point straight out. But for something like a snow cone, the normal will have to be averaged with the cone
geometry.Normals.Add(normalTransform.Transform(point).ToVector().ToUnit()); // the normal is the same as the point for a sphere (but no tranlate transform)
}
}
// This is north pole point
geometry.Positions.Add(transform.Transform(new Point3D(0, 0, radiusZ)));
geometry.Normals.Add(transform.Transform(new Vector3D(0, 0, 1)));
#endregion
#region Triangles - Rings
int zOffsetBottom = pointOffset;
int zOffsetTop;
for (int phiCntr = 0; phiCntr < numSegmentsPhi - 1; phiCntr++) // The top cone will be added after this loop
{
zOffsetTop = zOffsetBottom + pointsTheta.Length;
for (int thetaCntr = 0; thetaCntr < pointsTheta.Length - 1; thetaCntr++)
{
// Top/Left triangle
geometry.TriangleIndices.Add(zOffsetBottom + thetaCntr + 0);
geometry.TriangleIndices.Add(zOffsetTop + thetaCntr + 1);
geometry.TriangleIndices.Add(zOffsetTop + thetaCntr + 0);
// Bottom/Right triangle
geometry.TriangleIndices.Add(zOffsetBottom + thetaCntr + 0);
geometry.TriangleIndices.Add(zOffsetBottom + thetaCntr + 1);
geometry.TriangleIndices.Add(zOffsetTop + thetaCntr + 1);
}
// Connecting the last 2 points to the first 2
// Top/Left triangle
geometry.TriangleIndices.Add(zOffsetBottom + (pointsTheta.Length - 1) + 0);
geometry.TriangleIndices.Add(zOffsetTop); // wrapping back around
geometry.TriangleIndices.Add(zOffsetTop + (pointsTheta.Length - 1) + 0);
//.........這裏部分代碼省略.........
示例8: GetCircle2D
public static MeshGeometry3D GetCircle2D(int numSides, Transform3D transform, Transform3D normalTransform)
{
//NOTE: This also sets the texture coordinates
int pointOffset = 0;
Point[] pointsTheta = Math2D.GetCircle_Cached(numSides);
MeshGeometry3D retVal = new MeshGeometry3D();
#region Positions/Normals
for (int thetaCntr = 0; thetaCntr < pointsTheta.Length; thetaCntr++)
{
Point3D point = new Point3D(pointsTheta[thetaCntr].X, pointsTheta[thetaCntr].Y, 0d);
retVal.Positions.Add(transform.Transform(point));
Point texturePoint = new Point(.5d + (pointsTheta[thetaCntr].X * .5d), .5d + (pointsTheta[thetaCntr].Y * .5d));
retVal.TextureCoordinates.Add(texturePoint);
Vector3D normal = new Vector3D(0, 0, 1);
retVal.Normals.Add(normalTransform.Transform(normal));
}
#endregion
#region Add the triangles
// Start with 0,1,2
retVal.TriangleIndices.Add(pointOffset + 0);
retVal.TriangleIndices.Add(pointOffset + 1);
retVal.TriangleIndices.Add(pointOffset + 2);
int lowerIndex = 2;
int upperIndex = pointsTheta.Length - 1;
int lastUsedIndex = 0;
bool shouldBumpLower = true;
// Do the rest of the triangles
while (lowerIndex < upperIndex)
{
retVal.TriangleIndices.Add(pointOffset + lowerIndex);
retVal.TriangleIndices.Add(pointOffset + upperIndex);
retVal.TriangleIndices.Add(pointOffset + lastUsedIndex);
if (shouldBumpLower)
{
lastUsedIndex = lowerIndex;
lowerIndex++;
}
else
{
lastUsedIndex = upperIndex;
upperIndex--;
}
shouldBumpLower = !shouldBumpLower;
}
#endregion
return retVal;
}
示例9: GetPointsFromMesh
/// <summary>
/// This overload takes an actual mesh
/// </summary>
public static Point3D[] GetPointsFromMesh(MeshGeometry3D mesh, Transform3D transform = null)
{
if (mesh == null)
{
return null;
}
Point3D[] points = null;
if (mesh.TriangleIndices != null && mesh.TriangleIndices.Count > 0)
{
// Referenced points
points = mesh.TriangleIndices.Select(o => mesh.Positions[o]).ToArray();
}
else
{
// Directly used points
points = mesh.Positions.ToArray();
}
if (transform != null)
{
transform.Transform(points);
}
// Exit Function
return points;
}
示例10: EndCap_PlateHard
private static void EndCap_PlateHard(ref int pointOffset, ref double[] rotateAnglesForPerp, MeshGeometry3D geometry, Point[] pointsTheta, Transform3D transform, Transform3D normalTransform, TubeRingBase ring, bool isFirst)
{
Vector3D normal = normalTransform.Transform(new Vector3D(0, 0, 1)).ToUnit();
// Start with 0,1,2
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[0].X, pointsTheta[0].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[1].X, pointsTheta[1].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[2].X, pointsTheta[2].Y, 0d)));
geometry.Normals.Add(normal);
geometry.Normals.Add(normal);
geometry.Normals.Add(normal);
geometry.TriangleIndices.Add(pointOffset + 0);
geometry.TriangleIndices.Add(pointOffset + 1);
geometry.TriangleIndices.Add(pointOffset + 2);
int lowerIndex = 2;
int upperIndex = pointsTheta.Length - 1;
int lastUsedIndex = 0;
bool shouldBumpLower = true;
int localOffset = 3;
// Do the rest of the triangles
while (lowerIndex < upperIndex)
{
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[lowerIndex].X, pointsTheta[lowerIndex].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[upperIndex].X, pointsTheta[upperIndex].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[lastUsedIndex].X, pointsTheta[lastUsedIndex].Y, 0d)));
geometry.Normals.Add(normal);
geometry.Normals.Add(normal);
geometry.Normals.Add(normal);
geometry.TriangleIndices.Add(pointOffset + localOffset + 0);
geometry.TriangleIndices.Add(pointOffset + localOffset + 1);
geometry.TriangleIndices.Add(pointOffset + localOffset + 2);
if (shouldBumpLower)
{
lastUsedIndex = lowerIndex;
lowerIndex++;
}
else
{
lastUsedIndex = upperIndex;
upperIndex--;
}
shouldBumpLower = !shouldBumpLower;
localOffset += 3;
}
// Update ref param
pointOffset = geometry.Positions.Count;
}
示例11: GetRingSprtCap
private static void GetRingSprtCap(ref int pointOffset, MeshGeometry3D geometry, Transform3D transform, Point[] points, int numSides, double innerRadius, double outerRadius)
{
// Points/Normals
for (int cntr = 0; cntr < numSides; cntr++)
{
geometry.Positions.Add(transform.Transform(new Point3D(points[cntr].X * outerRadius, points[cntr].Y * outerRadius, 0d)));
geometry.Normals.Add(transform.Transform(new Vector3D(0, 0, 1)).ToUnit());
}
for (int cntr = 0; cntr < numSides; cntr++)
{
geometry.Positions.Add(transform.Transform(new Point3D(points[cntr].X * innerRadius, points[cntr].Y * innerRadius, 0d)));
geometry.Normals.Add(transform.Transform(new Vector3D(0, 0, 1)).ToUnit());
}
int zOffsetOuter = pointOffset;
int zOffsetInner = zOffsetOuter + numSides;
// Triangles
for (int cntr = 0; cntr < numSides - 1; cntr++)
{
// Bottom Right triangle
geometry.TriangleIndices.Add(zOffsetOuter + cntr + 0);
geometry.TriangleIndices.Add(zOffsetOuter + cntr + 1);
geometry.TriangleIndices.Add(zOffsetInner + cntr + 1);
// Top Left triangle
geometry.TriangleIndices.Add(zOffsetOuter + cntr + 0);
geometry.TriangleIndices.Add(zOffsetInner + cntr + 1);
geometry.TriangleIndices.Add(zOffsetInner + cntr + 0);
}
// Connecting the last 2 points to the first 2
// Bottom/Right triangle
geometry.TriangleIndices.Add(zOffsetOuter + (numSides - 1) + 0);
geometry.TriangleIndices.Add(zOffsetOuter);
geometry.TriangleIndices.Add(zOffsetInner);
// Top/Left triangle
geometry.TriangleIndices.Add(zOffsetOuter + (numSides - 1) + 0);
geometry.TriangleIndices.Add(zOffsetInner); // wrapping back around
geometry.TriangleIndices.Add(zOffsetInner + (numSides - 1) + 0);
pointOffset = geometry.Positions.Count;
}
示例12: EndCap_ConeHard
private static void EndCap_ConeHard(ref int pointOffset, ref double[] rotateAnglesForPerp, MeshGeometry3D geometry, Point[] pointsTheta, Transform3D transform, TubeRingPoint ring, double capHeight, bool isFirst)
{
Point3D tipPosition = transform.Transform(new Point3D(0, 0, capHeight));
int localOffset = 0;
for (int cntr = 0; cntr < pointsTheta.Length - 1; cntr++)
{
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[cntr].X, pointsTheta[cntr].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[cntr + 1].X, pointsTheta[cntr + 1].Y, 0d)));
geometry.Positions.Add(tipPosition);
Vector3D normal = GetNormal(geometry.Positions[pointOffset + localOffset + 0], geometry.Positions[pointOffset + localOffset + 1], geometry.Positions[pointOffset + localOffset + 2]);
geometry.Normals.Add(normal); // the normals point straight out of the face
geometry.Normals.Add(normal);
geometry.Normals.Add(normal);
geometry.TriangleIndices.Add(pointOffset + localOffset + 0);
geometry.TriangleIndices.Add(pointOffset + localOffset + 1);
geometry.TriangleIndices.Add(pointOffset + localOffset + 2);
localOffset += 3;
}
// The last triangle links back to zero
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[pointsTheta.Length - 1].X, pointsTheta[pointsTheta.Length - 1].Y, 0d)));
geometry.Positions.Add(transform.Transform(new Point3D(pointsTheta[0].X, pointsTheta[0].Y, 0d)));
geometry.Positions.Add(tipPosition);
Vector3D normal2 = GetNormal(geometry.Positions[pointOffset + localOffset + 0], geometry.Positions[pointOffset + localOffset + 1], geometry.Positions[pointOffset + localOffset + 2]);
geometry.Normals.Add(normal2); // the normals point straight out of the face
geometry.Normals.Add(normal2);
geometry.Normals.Add(normal2);
geometry.TriangleIndices.Add(pointOffset + localOffset + 0);
geometry.TriangleIndices.Add(pointOffset + localOffset + 1);
geometry.TriangleIndices.Add(pointOffset + localOffset + 2);
// Update ref param
pointOffset = geometry.Positions.Count;
}
示例13: RotateDNA_DoIt
private static ShipDNA RotateDNA_DoIt(ShipDNA dna, Quaternion rotation, Transform3D positionTransform)
{
ShipDNA retVal = UtilityCore.Clone(dna);
foreach (ShipPartDNA part in retVal.PartsByLayer.SelectMany(o => o.Value))
{
// Rotate the orientation
//part.Orientation = part.Orientation.RotateBy(rotation);
part.Orientation = rotation.RotateBy(part.Orientation);
// Apply a transform to the poisition
part.Position = positionTransform.Transform(part.Position);
//TODO: See if these need to be rotated as well
//part.Neurons;
//part.ExternalLinks;
//part.InternalLinks;
}
return retVal;
}
示例14: GetDodecahedron
public static Dodecahedron GetDodecahedron(double radius, Transform3D transform = null)
{
// This is 12 pentagons
#region Points
double t = (1d + Math.Sqrt(5d)) / 2d;
double t1 = 1d / t;
Point3D[] points = new Point3D[]
{
//(±1, ±1, ±1)
new Point3D(1, 1, 1), // 0
new Point3D(1, 1, -1), // 1
new Point3D(1, -1, 1), // 2
new Point3D(1, -1, -1), // 3
new Point3D(-1, 1, 1), // 4
new Point3D(-1, 1, -1), // 5
new Point3D(-1, -1, 1), // 6
new Point3D(-1, -1, -1), // 7
//(0, ±1/φ, ±φ)
new Point3D(0, t1, t), // 8
new Point3D(0, t1, -t), // 9
new Point3D(0, -t1, t), // 10
new Point3D(0, -t1, -t), // 11
//(±1/φ, ±φ, 0)
new Point3D(t1, t, 0), // 12
new Point3D(t1, -t, 0), // 13
new Point3D(-t1, t, 0), // 14
new Point3D(-t1, -t, 0), // 15
//(±φ, 0, ±1/φ)
new Point3D(t, 0, t1), // 16
new Point3D(t, 0, -t1), // 17
new Point3D(-t, 0, t1), // 18
new Point3D(-t, 0, -t1), // 19
};
double maxLength = points[8].ToVector().Length; // this represents the longest vector
double ratio = radius / maxLength;
points = points.Select(o => (o.ToVector() * ratio).ToPoint()).ToArray();
if (transform != null)
{
points = points.Select(o => transform.Transform(o)).ToArray();
}
#endregion
int[][] pentagonPolys = new int[][]
{
new int [] { 2, 10, 6, 15, 13 },
new int [] { 0, 8, 10, 2, 16 },
new int [] { 0, 12, 14, 4, 8 },
new int [] { 1, 9, 5, 14, 12 },
new int [] { 1, 17, 3, 11, 9 },
new int [] { 2, 13, 3, 17, 16 },
new int [] { 3, 13, 15, 7, 11 },
new int [] { 6, 18, 19, 7, 15 },
new int [] { 4, 18, 6, 10, 8 },
new int [] { 4, 14, 5, 19, 18 },
new int [] { 5, 9, 11, 7, 19 },
new int [] { 0, 16, 17, 1, 12 },
};
return new Dodecahedron(pentagonPolys, points);
}
示例15: ExportMesh
/// <summary>
/// The export mesh.
/// </summary>
/// <param name="m">
/// The m.
/// </param>
/// <param name="t">
/// The t.
/// </param>
public void ExportMesh(MeshGeometry3D m, Transform3D t)
{
if (m == null)
{
throw new ArgumentNullException("m");
}
if (t == null)
{
throw new ArgumentNullException("t");
}
// mapping from local indices (0-based) to the obj file indices (1-based)
var vertexIndexMap = new Dictionary<int, int>();
var textureIndexMap = new Dictionary<int, int>();
var normalIndexMap = new Dictionary<int, int>();
int index = 0;
if (m.Positions != null)
{
foreach (var v in m.Positions)
{
vertexIndexMap.Add(index++, this.vertexIndex++);
var p = t.Transform(v);
this.writer.WriteLine(
string.Format(
CultureInfo.InvariantCulture,
"v {0} {1} {2}",
p.X,
this.SwitchYZ ? p.Z : p.Y,
this.SwitchYZ ? -p.Y : p.Z));
}
this.writer.WriteLine(string.Format("# {0} vertices", index));
}
if (m.TextureCoordinates != null)
{
index = 0;
foreach (var vt in m.TextureCoordinates)
{
textureIndexMap.Add(index++, this.textureIndex++);
this.writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "vt {0} {1}", vt.X, 1 - vt.Y));
}
this.writer.WriteLine(string.Format("# {0} texture coordinates", index));
}
if (m.Normals != null && ExportNormals)
{
index = 0;
foreach (var vn in m.Normals)
{
normalIndexMap.Add(index++, this.normalIndex++);
this.writer.WriteLine(
string.Format(CultureInfo.InvariantCulture, "vn {0} {1} {2}", vn.X, vn.Y, vn.Z));
}
this.writer.WriteLine(string.Format("# {0} normals", index));
}
Func<int, string> formatIndices = i0 =>
{
bool hasTextureIndex = textureIndexMap.ContainsKey(i0);
bool hasNormalIndex = normalIndexMap.ContainsKey(i0);
if (hasTextureIndex && hasNormalIndex)
{
return string.Format("{0}/{1}/{2}", vertexIndexMap[i0], textureIndexMap[i0], normalIndexMap[i0]);
}
if (hasTextureIndex)
{
return string.Format("{0}/{1}", vertexIndexMap[i0], textureIndexMap[i0]);
}
if (hasNormalIndex)
{
return string.Format("{0}//{1}", vertexIndexMap[i0], normalIndexMap[i0]);
}
return vertexIndexMap[i0].ToString();
};
if (m.TriangleIndices != null)
{
for (int i = 0; i < m.TriangleIndices.Count; i += 3)
{
int i0 = m.TriangleIndices[i];
int i1 = m.TriangleIndices[i + 1];
int i2 = m.TriangleIndices[i + 2];
//.........這裏部分代碼省略.........