本文整理匯總了C#中System.Windows.Media.Media3D.Transform3D.TransformBounds方法的典型用法代碼示例。如果您正苦於以下問題:C# Transform3D.TransformBounds方法的具體用法?C# Transform3D.TransformBounds怎麽用?C# Transform3D.TransformBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Media.Media3D.Transform3D
的用法示例。
在下文中一共展示了Transform3D.TransformBounds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadModelVolmetic
/// <summary>
/// Volumes are calculated across axis where they are whole numbers (rounded to 0 decimal places).
/// </summary>
/// <param name="modelFile"></param>
/// <param name="scaleMultiplyierX"></param>
/// <param name="scaleMultiplyierY"></param>
/// <param name="scaleMultiplyierZ"></param>
/// <param name="transform"></param>
/// <param name="traceType"></param>
/// <param name="resetProgress"></param>
/// <param name="incrementProgress"></param>
/// <returns></returns>
public static CubeType[][][] ReadModelVolmetic(string modelFile, double scaleMultiplyierX, double scaleMultiplyierY, double scaleMultiplyierZ, Transform3D transform, ModelTraceVoxel traceType, Action<double, double> resetProgress, Action incrementProgress)
{
var model = MeshHelper.Load(modelFile, ignoreErrors: true);
// How far to check in from the proposed Volumetric edge.
// This number is just made up, but small enough that it still represents the corner edge of the Volumetric space.
// But still large enough that it isn't the exact corner.
const double offset = 0.00000456f;
if (scaleMultiplyierX > 0 && scaleMultiplyierY > 0 && scaleMultiplyierZ > 0 && scaleMultiplyierX != 1.0f && scaleMultiplyierY != 1.0f && scaleMultiplyierZ != 1.0f)
{
model.TransformScale(scaleMultiplyierX, scaleMultiplyierY, scaleMultiplyierZ);
}
var tbounds = model.Bounds;
if (transform != null)
tbounds = transform.TransformBounds(tbounds);
var xMin = (int)Math.Floor(tbounds.X);
var yMin = (int)Math.Floor(tbounds.Y);
var zMin = (int)Math.Floor(tbounds.Z);
var xMax = (int)Math.Ceiling(tbounds.X + tbounds.SizeX);
var yMax = (int)Math.Ceiling(tbounds.Y + tbounds.SizeY);
var zMax = (int)Math.Ceiling(tbounds.Z + tbounds.SizeZ);
var xCount = xMax - xMin;
var yCount = yMax - yMin;
var zCount = zMax - zMin;
var ccubic = ArrayHelper.Create<CubeType>(xCount, yCount, zCount);
if (resetProgress != null)
{
double count = (from GeometryModel3D gm in model.Children select gm.Geometry as MeshGeometry3D).Aggregate<MeshGeometry3D, double>(0, (current, g) => current + (g.TriangleIndices.Count / 3));
if (traceType == ModelTraceVoxel.ThinSmoothed || traceType == ModelTraceVoxel.ThickSmoothedUp)
{
count += (xCount * yCount * zCount * 3);
}
resetProgress.Invoke(0, count);
}
#region basic ray trace of every individual triangle.
foreach (var model3D in model.Children)
{
var gm = (GeometryModel3D)model3D;
var g = gm.Geometry as MeshGeometry3D;
var materials = gm.Material as MaterialGroup;
System.Windows.Media.Color color = Colors.Transparent;
if (materials != null)
{
var material = materials.Children.OfType<DiffuseMaterial>().FirstOrDefault();
if (material != null && material != null && material.Brush is SolidColorBrush)
{
color = ((SolidColorBrush)material.Brush).Color;
}
}
for (var t = 0; t < g.TriangleIndices.Count; t += 3)
{
if (incrementProgress != null)
{
incrementProgress.Invoke();
}
var p1 = g.Positions[g.TriangleIndices[t]];
var p2 = g.Positions[g.TriangleIndices[t + 1]];
var p3 = g.Positions[g.TriangleIndices[t + 2]];
if (transform != null)
{
p1 = transform.Transform(p1);
p2 = transform.Transform(p2);
p3 = transform.Transform(p3);
}
var minBound = MeshHelper.Min(p1, p2, p3).Floor();
var maxBound = MeshHelper.Max(p1, p2, p3).Ceiling();
Point3D[] rays;
for (var y = minBound.Y; y < maxBound.Y; y++)
{
for (var z = minBound.Z; z < maxBound.Z; z++)
//.........這裏部分代碼省略.........
示例2: ReadModelAsteroidVolmetic
// For a 1024 cubed asteroid, it takes approximately 6.5Gb of system memory.
public static MyVoxelMap ReadModelAsteroidVolmetic(Model3DGroup model, IList<MyMeshModel> mappedMesh, ScaleTransform3D scale, Transform3D rotateTransform, TraceType traceType, TraceCount traceCount, TraceDirection traceDirection,
Action<double, double> resetProgress, Action incrementProgress, Func<bool> checkCancel, Action complete)
{
var traceDirectionCount = 0;
var materials = new List<byte>();
var faceMaterials = new List<byte>();
foreach (var mesh in mappedMesh)
{
if (string.IsNullOrEmpty(mesh.Material))
materials.Add(0xff); // represent empty materials.
else
materials.Add(SpaceEngineersCore.Resources.GetMaterialIndex(mesh.Material));
if (string.IsNullOrEmpty(mesh.FaceMaterial))
faceMaterials.Add(0xff); // represent empty materials.
else
faceMaterials.Add(SpaceEngineersCore.Resources.GetMaterialIndex(mesh.FaceMaterial));
}
// How far to check in from the proposed Volumetric edge.
// This number is just made up, but small enough that it still represents the corner edge of the Volumetric space.
// But still large enough that it isn't the exact corner.
const double offset = 0.0000045f;
if (scale.ScaleX > 0 && scale.ScaleY > 0 && scale.ScaleZ > 0 && scale.ScaleX != 1.0f && scale.ScaleY != 1.0f && scale.ScaleZ != 1.0f)
{
model.TransformScale(scale.ScaleX, scale.ScaleY, scale.ScaleZ);
}
// Attempt to offset the model, so it's only caulated from zero (0) and up, instead of using zero (0) as origin.
//model.Transform = new TranslateTransform3D(-model.Bounds.X, -model.Bounds.Y, -model.Bounds.Z);
var tbounds = model.Bounds;
Matrix3D? rotate = null;
if (rotateTransform != null)
{
rotate = rotateTransform.Value;
tbounds = rotateTransform.TransformBounds(tbounds);
}
//model.Transform = new TranslateTransform3D(-tbounds.X, -tbounds.Y, -tbounds.Z);
// Add 2 to either side, to allow for material padding to expose internal materials.
var xMin = (int)Math.Floor(tbounds.X) - 2;
var yMin = (int)Math.Floor(tbounds.Y) - 2;
var zMin = (int)Math.Floor(tbounds.Z) - 2;
var xMax = (int)Math.Ceiling(tbounds.X + tbounds.SizeX) + 2;
var yMax = (int)Math.Ceiling(tbounds.Y + tbounds.SizeY) + 2;
var zMax = (int)Math.Ceiling(tbounds.Z + tbounds.SizeZ) + 2;
var xCount = (xMax - xMin).RoundUpToNearest(64);
var yCount = (yMax - yMin).RoundUpToNearest(64);
var zCount = (zMax - zMin).RoundUpToNearest(64);
Debug.WriteLine("Approximate Size: {0}x{1}x{2}", Math.Ceiling(tbounds.X + tbounds.SizeX) - Math.Floor(tbounds.X), Math.Ceiling(tbounds.Y + tbounds.SizeY) - Math.Floor(tbounds.Y), Math.Ceiling(tbounds.Z + tbounds.SizeZ) - Math.Floor(tbounds.Z));
Debug.WriteLine("Bounds Size: {0}x{1}x{2}", xCount, yCount, zCount);
var finalCubic = ArrayHelper.Create<byte>(xCount, yCount, zCount);
var finalMater = ArrayHelper.Create<byte>(xCount, yCount, zCount);
if (resetProgress != null)
{
long triangles = (from GeometryModel3D gm in model.Children select gm.Geometry as MeshGeometry3D).Aggregate<MeshGeometry3D, long>(0, (current, g) => current + (g.TriangleIndices.Count / 3));
long rays = 0;
if ((traceDirection & TraceDirection.X) == TraceDirection.X)
rays += ((yMax - yMin) * (zMax - zMin));
if ((traceDirection & TraceDirection.Y) == TraceDirection.Y)
rays += ((xMax - xMin) * (zMax - zMin));
if ((traceDirection & TraceDirection.Z) == TraceDirection.Z)
rays += ((xMax - xMin) * (yMax - yMin));
resetProgress.Invoke(0, rays * triangles);
}
if (checkCancel != null && checkCancel.Invoke())
{
if (complete != null)
complete.Invoke();
return null;
}
#region basic ray trace of every individual triangle.
// Start from the last mesh, which represents the bottom of the UI stack, and overlay each other mesh on top of it.
for (var modelIdx = mappedMesh.Count - 1; modelIdx >= 0; modelIdx--)
{
Debug.WriteLine("Model {0}", modelIdx);
var modelCubic = new byte[xCount][][];
var modelMater = new byte[xCount][][];
for (var x = 0; x < xCount; x++)
{
modelCubic[x] = new byte[yCount][];
modelMater[x] = new byte[yCount][];
for (var y = 0; y < yCount; y++)
//.........這裏部分代碼省略.........