本文整理汇总了C#中Sandbox.Game.Entities.MyVoxelBase类的典型用法代码示例。如果您正苦于以下问题:C# MyVoxelBase类的具体用法?C# MyVoxelBase怎么用?C# MyVoxelBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyVoxelBase类属于Sandbox.Game.Entities命名空间,在下文中一共展示了MyVoxelBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyVoxelPhysicsBody
internal MyVoxelPhysicsBody(MyVoxelBase voxelMap,float phantomExtend): base(voxelMap, RigidBodyFlag.RBF_STATIC)
{
m_phantomExtend = phantomExtend;
m_voxelMap = voxelMap;
Vector3I storageSize = m_voxelMap.Size;
Vector3I numCels = storageSize >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS;
m_cellsOffset = m_voxelMap.StorageMin >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS;
HkUniformGridShape shape = new HkUniformGridShape(
new HkUniformGridShapeArgs()
{
CellsCount = numCels,
CellSize = MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES,
CellOffset = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF,
CellExpand = MyVoxelConstants.VOXEL_SIZE_IN_METRES,
});
shape.SetShapeRequestHandler(RequestShapeBlocking);
CreateFromCollisionObject(shape, -m_voxelMap.SizeInMetresHalf, m_voxelMap.WorldMatrix, collisionFilter: MyPhysics.VoxelCollisionLayer);
shape.Base.RemoveReference();
if (ENABLE_AABB_PHANTOM)
{
m_aabbPhantom = new Havok.HkpAabbPhantom(new BoundingBox(Vector3.Zero, m_voxelMap.SizeInMetres), 0);
m_aabbPhantom.CollidableAdded = AabbPhantom_CollidableAdded;
m_aabbPhantom.CollidableRemoved = AabbPhantom_CollidableRemoved;
}
if (MyFakes.ENABLE_PHYSICS_HIGH_FRICTION)
Friction = 0.65f;
MaterialType = Sandbox.Common.MyMaterialType.ROCK;
}
示例2: MyVoxelPhysicsBody
internal MyVoxelPhysicsBody(MyVoxelBase voxelMap, float phantomExtend, float predictionSize = 3.0f, bool lazyPhysics = false)
: base(voxelMap, RigidBodyFlag.RBF_STATIC)
{
ProfilerShort.Begin("MyVoxelPhysicsBody(");
InvalidCells = new HashSet<Vector3I>[2];
InvalidCells[0] = new HashSet<Vector3I>();
InvalidCells[1] = new HashSet<Vector3I>();
m_predictionSize = predictionSize;
m_phantomExtend = phantomExtend;
m_voxelMap = voxelMap;
Vector3I storageSize = m_voxelMap.Size;
Vector3I numCels = storageSize >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS;
m_cellsOffset = m_voxelMap.StorageMin >> MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS;
if (!MyFakes.ENABLE_LAZY_VOXEL_PHYSICS || !lazyPhysics || !ENABLE_AABB_PHANTOM)
{
CreateRigidBodies();
}
ProfilerShort.End();
MaterialType = MyMaterialType.ROCK;
}
示例3: RemoveVoxelMap
public void RemoveVoxelMap(MyVoxelBase voxelMap)
{
if (m_voxelMapsByEntityId.Remove(voxelMap.EntityId))
{
var render = voxelMap.Render;
if (render is MyRenderComponentVoxelMap)
{
var clipMapId = (render as MyRenderComponentVoxelMap).ClipmapId;
m_renderComponentsByClipmapId.Remove(clipMapId);
}
}
}
示例4: HideTrianglesAfterExplosion
// Blends-out triangles affected by explosion (radius + some safe delta). Triangles there have zero alpha are flaged to not-draw at all.
public static void HideTrianglesAfterExplosion(MyVoxelBase voxelMap, ref BoundingSphereD explosionSphere)
{
VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyDecals::HideTrianglesAfterExplosion");
//MyMwcVector3Int renderCellCoord = voxelMap.GetVoxelRenderCellCoordinateFromMeters(ref explosionSphere.Center);
//m_decalsForVoxels.HideTrianglesAfterExplosion(voxelMap.VoxelMapId, ref renderCellCoord, ref explosionSphere);
foreach (uint id in voxelMap.Render.RenderObjectIDs)
{
VRageRender.MyRenderProxy.HideDecals(id, explosionSphere.Center, (float)explosionSphere.Radius);
}
VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
}
示例5: Add
public void Add(MyVoxelBase voxelMap)
{
if (!Exist(voxelMap))
{
m_voxelMapsByEntityId.Add(voxelMap.EntityId, voxelMap);
// On dedicated servers, ClipmapIDs are all 0, but it's fine since there is no rendering anyway.
var render = voxelMap.Render;
if (render is MyRenderComponentVoxelMap)
{
var clipMapId= (render as MyRenderComponentVoxelMap).ClipmapId;
m_renderComponentsByClipmapId[clipMapId] = render as MyRenderComponentVoxelMap;
}
}
}
示例6: Add
public void Add(MatrixD worldMatrix, BoundingBox box, Vector4I id, MyVoxelBase voxel)
{
if (m_list.Count > 1900)
m_list.ClearList();
voxel = voxel.RootVoxel;
box.Translate(-voxel.SizeInMetresHalf);
//box.Translate(voxel.StorageMin);
m_list.Add(new PredictionInfo
{
Id = id,
Bounds = MyOrientedBoundingBoxD.Create((BoundingBoxD)box, voxel.WorldMatrix),
Body = voxel
});
}
示例7: MyVoxelNavigationMesh
public MyVoxelNavigationMesh(MyVoxelBase voxelMap, MyNavmeshCoordinator coordinator, Func<long> timestampFunction)
: base(coordinator.Links, 16, timestampFunction)
{
m_voxelMap = voxelMap;
m_cellSize = m_voxelMap.SizeInMetres / m_voxelMap.Storage.Geometry.CellsCount * (1 << NAVMESH_LOD);
m_processedCells = new MyVector3ISet();
m_markedForAddition = new MyVector3ISet();
m_toAdd = new MyBinaryStructHeap<float, Vector3I>(128);
m_connectionHelper = new MyVoxelConnectionHelper();
m_navmeshCoordinator = coordinator;
m_higherLevel = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
m_higherLevelHelper = new MyVoxelHighLevelHelper(this);
m_debugCellEdges = new Dictionary<ulong, List<DebugDrawEdge>>();
voxelMap.Storage.RangeChanged += OnStorageChanged;
}
示例8: CutOutShape
public static ulong CutOutShape(MyVoxelBase voxelMap, MyShape shape)
{
Vector3I minCorner, maxCorner, numCells;
GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out numCells);
ulong changedVolumeAmount = 0;
for (var itCells = new Vector3I.RangeIterator(ref Vector3I.Zero, ref numCells); itCells.IsValid(); itCells.MoveNext())
{
Vector3I cellMinCorner, cellMaxCorner;
GetCellCorners(ref minCorner, ref maxCorner, ref itCells, out cellMinCorner, out cellMaxCorner);
var cacheMin = cellMinCorner - 1;
var cacheMax = cellMaxCorner + 1;
voxelMap.Storage.ClampVoxelCoord(ref cacheMin);
voxelMap.Storage.ClampVoxelCoord(ref cacheMax);
ulong removedSum = 0;
m_cache.Resize(cacheMin, cacheMax);
voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.Content, 0, ref cacheMin, ref cacheMax);
for (var it = new Vector3I.RangeIterator(ref cellMinCorner, ref cellMaxCorner); it.IsValid(); it.MoveNext())
{
var relPos = it.Current - cacheMin; // get original amount
var original = m_cache.Content(ref relPos);
if (original == MyVoxelConstants.VOXEL_CONTENT_EMPTY) // if there is nothing to remove
continue;
Vector3D vpos;
MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref it.Current, out vpos);
var volume = shape.GetVolume(ref vpos);
if (volume == 0f) // if there is no intersection
continue;
var toRemove = (int)(MyVoxelConstants.VOXEL_CONTENT_FULL - (volume * MyVoxelConstants.VOXEL_CONTENT_FULL));
var newVal = Math.Min(toRemove, original);
ulong removed = (ulong)Math.Abs(original - newVal);
m_cache.Content(ref relPos, (byte)newVal);
removedSum += removed;
}
if (removedSum > 0)
{
RemoveSmallVoxelsUsingChachedVoxels(); // must stay because of the around when filling voxels
voxelMap.Storage.WriteRange(m_cache, MyStorageDataTypeFlags.Content, ref cacheMin, ref cacheMax);
}
changedVolumeAmount += removedSum;
}
return changedVolumeAmount;
}
示例9: FillInShape
public static ulong FillInShape(MyVoxelBase voxelMap, MyShape shape, byte materialIdx)
{
Vector3I minCorner, maxCorner, numCells;
ulong retValue = 0;
GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out numCells);
for (var itCells = new Vector3I.RangeIterator(ref Vector3I.Zero, ref numCells); itCells.IsValid(); itCells.MoveNext())
{
Vector3I cellMinCorner, cellMaxCorner;
GetCellCorners(ref minCorner, ref maxCorner, ref itCells, out cellMinCorner, out cellMaxCorner);
Vector3I originalMinCorner = cellMinCorner;
Vector3I originalMaxCorner = cellMaxCorner;
voxelMap.Storage.ClampVoxelCoord(ref cellMinCorner, VOXEL_CLAMP_BORDER_DISTANCE);
voxelMap.Storage.ClampVoxelCoord(ref cellMaxCorner, VOXEL_CLAMP_BORDER_DISTANCE);
ClampingInfo minCornerClamping = CheckForClamping(originalMinCorner, cellMinCorner);
ClampingInfo maxCornerClamping = CheckForClamping(originalMaxCorner, cellMaxCorner);
m_cache.Resize(cellMinCorner, cellMaxCorner);
voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.ContentAndMaterial, 0, ref cellMinCorner, ref cellMaxCorner);
ulong filledSum = 0;
for (var it = new Vector3I.RangeIterator(ref cellMinCorner, ref cellMaxCorner); it.IsValid(); it.MoveNext())
{
var relPos = it.Current - cellMinCorner; // get original amount
var original = m_cache.Content(ref relPos);
if (original == MyVoxelConstants.VOXEL_CONTENT_FULL) // if there is nothing to add
continue;
//if there was some claping, fill the clamp region with material
if ((it.Current.X == cellMinCorner.X && minCornerClamping.X) || (it.Current.X == cellMaxCorner.X && maxCornerClamping.X) ||
(it.Current.Y == cellMinCorner.Y && minCornerClamping.Y) || (it.Current.Y == cellMaxCorner.Y && maxCornerClamping.Y) ||
(it.Current.Z == cellMinCorner.Z && minCornerClamping.Z) || (it.Current.Z == cellMaxCorner.Z && maxCornerClamping.Z))
{
m_cache.Material(ref relPos, materialIdx);
continue;
}
Vector3D vpos;
MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref it.Current, out vpos);
var volume = shape.GetVolume(ref vpos);
if (volume <= 0f) // there is nothing to fill
continue;
m_cache.Material(ref relPos, materialIdx); // set material
var toFill = (int)(volume * MyVoxelConstants.VOXEL_CONTENT_FULL);
long newVal = MathHelper.Clamp(original + toFill, 0, Math.Max(original, toFill));
m_cache.Content(ref relPos, (byte)newVal);
filledSum += (ulong)(newVal - original);
}
if (filledSum > 0)
{
RemoveSmallVoxelsUsingChachedVoxels();
voxelMap.Storage.WriteRange(m_cache, MyStorageDataTypeFlags.ContentAndMaterial, ref cellMinCorner, ref cellMaxCorner);
}
retValue += filledSum;
}
return retValue;
}
示例10: MakeCrater
public static void MakeCrater(MyVoxelBase voxelMap, BoundingSphereD sphere, Vector3 normal, MyVoxelMaterialDefinition material)
{
ProfilerShort.Begin("MakeCrater");
Vector3I minCorner, maxCorner;
{
Vector3D sphereMin = sphere.Center - (sphere.Radius - MyVoxelConstants.VOXEL_SIZE_IN_METRES);
Vector3D sphereMax = sphere.Center + (sphere.Radius + MyVoxelConstants.VOXEL_SIZE_IN_METRES);
MyVoxelCoordSystems.WorldPositionToVoxelCoord(voxelMap.PositionLeftBottomCorner, ref sphereMin, out minCorner);
MyVoxelCoordSystems.WorldPositionToVoxelCoord(voxelMap.PositionLeftBottomCorner, ref sphereMax, out maxCorner);
}
voxelMap.Storage.ClampVoxelCoord(ref minCorner);
voxelMap.Storage.ClampVoxelCoord(ref maxCorner);
// We are tracking which voxels were changed, so we can invalidate only needed cells in the cache
bool changed = false;
ProfilerShort.Begin("Reading cache");
m_cache.Resize(minCorner, maxCorner);
voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.ContentAndMaterial, 0, ref minCorner, ref maxCorner);
ProfilerShort.End();
ProfilerShort.Begin("Changing cache");
int removedVoxelContent = 0;
Vector3I tempVoxelCoord;
Vector3I cachePos;
for (tempVoxelCoord.Z = minCorner.Z, cachePos.Z = 0; tempVoxelCoord.Z <= maxCorner.Z; tempVoxelCoord.Z++, ++cachePos.Z)
{
for (tempVoxelCoord.Y = minCorner.Y, cachePos.Y = 0; tempVoxelCoord.Y <= maxCorner.Y; tempVoxelCoord.Y++, ++cachePos.Y)
{
for (tempVoxelCoord.X = minCorner.X, cachePos.X = 0; tempVoxelCoord.X <= maxCorner.X; tempVoxelCoord.X++, ++cachePos.X)
{
Vector3D voxelPosition;
MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref tempVoxelCoord, out voxelPosition);
float addDist = (float)(voxelPosition - sphere.Center).Length();
float addDiff = (float)(addDist - sphere.Radius);
byte newContent;
if (addDiff > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)
{
newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
}
else if (addDiff < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)
{
newContent = MyVoxelConstants.VOXEL_CONTENT_FULL;
}
else
{
// This formula will work even if diff is positive or negative
newContent = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - addDiff / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL);
}
byte originalContent = m_cache.Content(ref cachePos);
if (newContent > originalContent && originalContent > 0)
{
if (material != null)
{
m_cache.Material(ref cachePos, material.Index);
}
changed = true;
m_cache.Content(ref cachePos, newContent);
}
float delDist = (float)(voxelPosition - (sphere.Center + (float)sphere.Radius * 0.7f * normal)).Length();
float delDiff = (float)(delDist - sphere.Radius);
byte contentToRemove;
if (delDiff > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)
{
contentToRemove = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
}
else if (delDiff < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)
{
contentToRemove = MyVoxelConstants.VOXEL_CONTENT_FULL;
}
else
{
// This formula will work even if diff is positive or negative
contentToRemove = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - delDiff / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL);
}
originalContent = m_cache.Content(ref cachePos);
if (originalContent > MyVoxelConstants.VOXEL_CONTENT_EMPTY && contentToRemove > MyVoxelConstants.VOXEL_CONTENT_EMPTY)
{
changed = true;
int newVal = originalContent - contentToRemove;
if (newVal < MyVoxelConstants.VOXEL_CONTENT_EMPTY)
newVal = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
m_cache.Content(ref cachePos, (byte)newVal);
removedVoxelContent += originalContent - newVal;
}
float setDist = (float)(voxelPosition - (sphere.Center - (float)sphere.Radius * 0.5f * normal)).Length();
//.........这里部分代码省略.........
示例11: TestPlacementVoxelMapOverlap
public static bool TestPlacementVoxelMapOverlap(
MyVoxelBase voxelMap,
ref MyGridPlacementSettings settings,
ref BoundingBoxD localAabb,
ref MatrixD worldMatrix,
bool touchingStaticGrid = false)
{
ProfilerShort.Begin("TestPlacementVoxelMapOverlap");
var worldAabb = localAabb.Transform(ref worldMatrix);
const int IntersectsOrInside = 1;
const int Outside = 2;
int overlapState = Outside;
if (voxelMap == null)
voxelMap = MySession.Static.VoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref worldAabb, null);
if (voxelMap != null && voxelMap.IsAnyAabbCornerInside(ref worldMatrix, localAabb))
{
overlapState = IntersectsOrInside;
}
bool testPassed = true;
switch (overlapState)
{
case IntersectsOrInside:
testPassed = settings.Penetration.MaxAllowed > 0;
break;
case Outside:
testPassed = settings.Penetration.MinAllowed <= 0 || (settings.CanAnchorToStaticGrid && touchingStaticGrid);
break;
default:
Debug.Fail("Invalid branch.");
break;
}
ProfilerShort.End();
return testPassed;
}
示例12: RayCastGround
private MyStringHash RayCastGround()
{
MyStringHash walkSurfaceMaterial = new MyStringHash();
float maxDistValue = MyConstants.DEFAULT_GROUND_SEARCH_DISTANCE;
var from = m_character.PositionComp.GetPosition() + m_character.PositionComp.WorldMatrix.Up * 0.5; //(needs some small distance from the bottom or the following call to HavokWorld.CastRay will find no hits)
var to = from + m_character.PositionComp.WorldMatrix.Down * maxDistValue;
MyPhysics.CastRay(from, to, m_hits, MyPhysics.CollisionLayers.CharacterCollisionLayer);
// Skips invalid hits (null body, self character)
int index = 0;
while ((index < m_hits.Count) && ((m_hits[index].HkHitInfo.Body == null) || (m_hits[index].HkHitInfo.GetHitEntity() == Entity.Components)))
{
index++;
}
if (m_hits.Count == 0)
{
if ((m_standingOnGrid != null || m_standingOnVoxel != null) && ShouldUpdateSoundEmitters)
{
m_standingOnGrid = null;
m_standingOnVoxel = null;
MyEntity3DSoundEmitter.UpdateEntityEmitters(true, true, false);
}
else
{
m_standingOnGrid = null;
m_standingOnVoxel = null;
}
}
if (index < m_hits.Count)
{
// We must take only closest hit (others are hidden behind)
var h = m_hits[index];
var entity = h.HkHitInfo.GetHitEntity();
var sqDist = Vector3D.DistanceSquared((Vector3D)h.Position, from);
if (sqDist < maxDistValue * maxDistValue)
{
var cubeGrid = entity as MyCubeGrid;
var voxelBase = entity as MyVoxelBase;
if (((cubeGrid != null && m_standingOnGrid != cubeGrid) || (voxelBase != null && m_standingOnVoxel != voxelBase)) && ShouldUpdateSoundEmitters)
{
m_standingOnGrid = cubeGrid;
m_standingOnVoxel = voxelBase;
MyEntity3DSoundEmitter.UpdateEntityEmitters(true, true, true);
}
else
{
m_standingOnGrid = cubeGrid;
m_standingOnVoxel = voxelBase;
}
if(cubeGrid != null || voxelBase != null)
m_jumpReady = true;
if (cubeGrid != null)
walkSurfaceMaterial = cubeGrid.Physics.GetMaterialAt(h.Position + m_character.PositionComp.WorldMatrix.Down * 0.1f);
else if (voxelBase != null && voxelBase.Storage != null && voxelBase.Storage.DataProvider != null)
{
var materialDefinition = voxelBase.GetMaterialAt(ref h.Position);
if (materialDefinition != null)
walkSurfaceMaterial = MyStringHash.GetOrCompute(materialDefinition.MaterialTypeName);
}
if (walkSurfaceMaterial.ToString().Length == 0)
walkSurfaceMaterial = MyMaterialType.ROCK;
}
}
m_hits.Clear();
return walkSurfaceMaterial;
}
示例13: SendCutOutRequest
public override void SendCutOutRequest(MyVoxelBase voxel)
{
voxel.RequestVoxelOperationCapsule(A, B, Radius, Transformation, 0, OperationType.Cut);
}
示例14: SendFillRequest
public override void SendFillRequest(MyVoxelBase voxel, byte newMaterialIndex)
{
voxel.RequestVoxelOperationRamp(Boundaries, RampNormal, RampNormalW, Transformation, newMaterialIndex, OperationType.Fill);
}
示例15: AddVoxelMesh
private void AddVoxelMesh(MyVoxelBase voxelBase, IMyStorage storage, Dictionary<Vector3I, MyIsoMesh> cache, float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List<BoundingBoxD> bbList)
{
bool useCache = cache != null;
if (useCache)
CheckCacheValidity();
obb.HalfExtent += new Vector3D(border, 0, border);
BoundingBoxD bb = obb.GetAABB();
int aabbSideSide = (int)Math.Round(bb.HalfExtents.Max() * 2);
bb = new BoundingBoxD(bb.Min, bb.Min + aabbSideSide);
bb.Translate(obb.Center - bb.Center);
// For debug
bbList.Add(new BoundingBoxD(bb.Min, bb.Max));
bb = (BoundingBoxD)bb.TransformFast(voxelBase.PositionComp.WorldMatrixInvScaled);
bb.Translate(voxelBase.SizeInMetresHalf);
Vector3I min = Vector3I.Round(bb.Min);
Vector3I max = min + aabbSideSide;
Vector3I geomMin, geomMax;
MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref min, out geomMin);
MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref max, out geomMax);
var cullBox = obb;
cullBox.Transform(voxelBase.PositionComp.WorldMatrixInvScaled);
cullBox.Center += voxelBase.SizeInMetresHalf;
ProfilerShort.Begin("WOOOORK");
Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref geomMin, ref geomMax);
MyCellCoord coord = new MyCellCoord();
BoundingBox localAabb;
coord.Lod = NAVMESH_LOD;
int hits = 0;
MyIsoMesh gMesh;
Vector3 offset = originPosition - voxelBase.PositionLeftBottomCorner;
// Calculate rotation
Vector3 gravityVector = -Vector3.Normalize(GameSystems.MyGravityProviderSystem.CalculateTotalGravityInPoint(originPosition));
Vector3 forwardVector = Vector3.CalculatePerpendicularVector(gravityVector);
Quaternion quaternion = Quaternion.CreateFromForwardUp(forwardVector, gravityVector);
Matrix rotation = Matrix.CreateFromQuaternion(Quaternion.Inverse(quaternion));
Matrix ownRotation = voxelBase.PositionComp.WorldMatrix.GetOrientation();
while (it.IsValid())
{
ProfilerShort.Begin("ITERATOR");
if (useCache && cache.TryGetValue(it.Current, out gMesh))
{
if (gMesh != null)
{
AddMeshTriangles(gMesh, offset, rotation, ownRotation);
}
it.MoveNext();
ProfilerShort.End();
continue;
}
coord.CoordInLod = it.Current;
MyVoxelCoordSystems.GeometryCellCoordToLocalAABB(ref coord.CoordInLod, out localAabb);
if (!cullBox.Intersects(ref localAabb))
{
hits++;
it.MoveNext();
ProfilerShort.End();
continue;
}
ProfilerShort.End();
var debugBB = new BoundingBoxD(localAabb.Min, localAabb.Max).Translate(-voxelBase.SizeInMetresHalf);
bbList.Add(debugBB);
ProfilerShort.Begin("Mesh Calc");
var voxelStart = coord.CoordInLod * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS - 1;
var voxelEnd = voxelStart + MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS //- 1
+ 1 // overlap to neighbor so geometry is stitched together within same LOD
+ 1; // for eg. 9 vertices in row we need 9 + 1 samples (voxels)
var generatedMesh = MyPrecalcComponent.IsoMesher.Precalc(storage, NAVMESH_LOD, voxelStart, voxelEnd, false, false, true);
ProfilerShort.End();
if (useCache)
cache[it.Current] = generatedMesh;
if (generatedMesh != null)
{
ProfilerShort.Begin("Mesh NOT NULL");
AddMeshTriangles(generatedMesh, offset, rotation, ownRotation);
ProfilerShort.End();
}
it.MoveNext();
}
ProfilerShort.End();
}