本文整理汇总了C#中HkdBreakableShape类的典型用法代码示例。如果您正苦于以下问题:C# HkdBreakableShape类的具体用法?C# HkdBreakableShape怎么用?C# HkdBreakableShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HkdBreakableShape类属于命名空间,在下文中一共展示了HkdBreakableShape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: IsFixed
public static bool IsFixed(HkdBreakableShape breakableShape)
{
System.Diagnostics.Debug.Assert(m_tmpInfos.Count == 0, "");
if (!breakableShape.IsValid())
return false;
if ((breakableShape.UserObject & (uint)HkdBreakableShape.Flags.IS_FIXED) != 0)
{
return true;
}
else
{
Debug.Assert(m_tmpInfos.Count == 0);
breakableShape.GetChildren(m_tmpInfos);
foreach (var child in m_tmpInfos)
{
if ((child.Shape.UserObject & (uint)HkdBreakableShape.Flags.IS_FIXED) != 0)
{
m_tmpInfos.Clear();
return true;
}
}
m_tmpInfos.Clear();
}
return false;
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:25,代码来源:MyDestructionHelper.cs
示例2: EnqueShape
public void EnqueShape(string model, MyDefinitionId id, HkdBreakableShape shape)
{
using (m_poolLock.AcquireExclusiveUsing())
{
if (!m_pools.ContainsKey(id))
m_pools[id] = new Dictionary<string, ConcurrentQueue<HkdBreakableShape>>();
if (!m_pools[id].ContainsKey(model))
m_pools[id][model] = new ConcurrentQueue<HkdBreakableShape>();
}
m_pools[id][model].Enqueue(shape);
m_missing--;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:13,代码来源:MyBreakableShapeManager.cs
示例3: CreateFracturePiece
/// <summary>
///
/// </summary>
/// <param name="shape">Piece takes ownership of shape so clone it first</param>
/// <param name="worldMatrix"></param>
/// <param name="definition"> without definition the piece wont save</param>
/// <returns></returns>
public static MyFracturedPiece CreateFracturePiece(HkdBreakableShape shape, HkdWorld world, ref MatrixD worldMatrix, bool isStatic, MyDefinitionId? definition, bool sync)
{
System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server");
var fracturedPiece = CreateFracturePiece(ref shape, world, ref worldMatrix, isStatic);
if (definition.HasValue)
{
fracturedPiece.OriginalBlocks.Clear();
fracturedPiece.OriginalBlocks.Add(definition.Value);
MyPhysicalModelDefinition def;
if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(definition.Value, out def))
fracturedPiece.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
}
else
fracturedPiece.Save = false;
if (sync)
MySyncDestructions.CreateFracturePiece((Sandbox.Common.ObjectBuilders.MyObjectBuilder_FracturedPiece)fracturedPiece.GetObjectBuilder());
return fracturedPiece;
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:28,代码来源:MyDestructionHelper.cs
示例4: DontCreateFracture
private static bool DontCreateFracture(HkdBreakableShape breakableShape)
{
if (!breakableShape.IsValid())
return false;
return (breakableShape.UserObject & (uint)HkdBreakableShape.Flags.DONT_CREATE_FRACTURE_PIECE) != 0;
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:6,代码来源:MyDestructionHelper.cs
示例5: CreateBody
protected override void CreateBody(ref HkShape shape, HkMassProperties? massProperties)
{
if (MyPerGameSettings.Destruction)// && shape.ShapeType == HkShapeType.StaticCompound)
{
ProfilerShort.Begin("CreateGridBody");
HkdBreakableShape breakable;
HkMassProperties massProps = massProperties.HasValue ? massProperties.Value : new HkMassProperties();
if (!Shape.BreakableShape.IsValid())
Shape.CreateBreakableShape();
breakable = Shape.BreakableShape;
if (!breakable.IsValid())
{
breakable = new HkdBreakableShape(shape);
if (massProperties.HasValue)
{
var mp = massProperties.Value;
breakable.SetMassProperties(ref mp);
}
else
breakable.SetMassRecursively(50);
}
else
breakable.BuildMassProperties(ref massProps);
shape = breakable.GetShape(); //doesnt add reference
HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();
rbInfo.AngularDamping = m_angularDamping;
rbInfo.LinearDamping = m_linearDamping;
rbInfo.SolverDeactivation = m_grid.IsStatic ? InitialSolverDeactivation : HkSolverDeactivation.Low;
rbInfo.ContactPointCallbackDelay = ContactPointDelay;
rbInfo.Shape = shape;
rbInfo.SetMassProperties(massProps);
//rbInfo.Position = Entity.PositionComp.GetPosition(); //obsolete with large worlds?
GetInfoFromFlags(rbInfo, Flags);
HkRigidBody rb = new HkRigidBody(rbInfo);
rb.EnableDeactivation = true;
BreakableBody = new HkdBreakableBody(breakable, rb, MyPhysics.SingleWorld.DestructionWorld, Matrix.Identity);
//DestructionBody.ConnectToWorld(HavokWorld, 0.05f);
BreakableBody.AfterReplaceBody += FracturedBody_AfterReplaceBody;
//RigidBody.SetWorldMatrix(Entity.PositionComp.WorldMatrix);
//breakable.Dispose();
ProfilerShort.End();
}
else
{
base.CreateBody(ref shape, massProperties);
}
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:55,代码来源:MyGridPhysics.cs
示例6: DrawBreakableShape
private void DrawBreakableShape(HkdBreakableShape breakableShape, MatrixD worldMatrix, float alpha, ref int shapeIndex, string customText = null, bool isPhantom = false)
{
//VRageRender.MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, , Color.White, 1, false);
DrawCollisionShape(breakableShape.GetShape(), worldMatrix, alpha, ref shapeIndex, breakableShape.Name + " Strength: " + breakableShape.GetStrenght() + " Static:" + breakableShape.IsFixed());
if (!string.IsNullOrEmpty(breakableShape.Name) && breakableShape.Name != "PineTree175m_v2_001" && breakableShape.IsFixed())
{
}
DebugShapesPositions[breakableShape.Name] = worldMatrix.Translation;
List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
breakableShape.GetChildren(children);
Vector3 parentCom = breakableShape.CoM;
foreach (var shapeInst in children)
{
Matrix transform = shapeInst.GetTransform();
// transform.Translation += (shapeInst.Shape.CoM - parentCom);
Matrix trWorld = transform * worldMatrix * Matrix.CreateTranslation(Vector3.Right * 2);
DrawBreakableShape(shapeInst.Shape, trWorld, alpha, ref shapeIndex);
}
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:24,代码来源:MyPhysicsBody.cs
示例7: CreateFracturePiece
/// <summary>
///
/// </summary>
/// <param name="shape">Piece takes ownership of shape so clone it first</param>
/// <param name="worldMatrix"></param>
/// <param name="definition"> without definition the piece wont save</param>
/// <returns></returns>
public static MyFracturedPiece CreateFracturePiece(HkdBreakableShape shape, HkdWorld world, ref MatrixD worldMatrix, bool isStatic, MyDefinitionId? definition, bool sync)
{
System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server");
var fracturedPiece = CreateFracturePiece(ref shape, world, ref worldMatrix, isStatic);
if (definition.HasValue)
{
fracturedPiece.OriginalBlocks.Clear();
fracturedPiece.OriginalBlocks.Add(definition.Value);
MyPhysicalModelDefinition def;
if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(definition.Value, out def))
fracturedPiece.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
}
else
fracturedPiece.Save = false;
// Check valid shapes from block definitions.
if (fracturedPiece.Save && MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK)
fracturedPiece.DebugCheckValidShapes();
ProfilerShort.Begin("MyEntities.Add");
MyEntities.RaiseEntityCreated(fracturedPiece);
MyEntities.Add(fracturedPiece);
ProfilerShort.End();
return fracturedPiece;
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:35,代码来源:MyDestructionHelper.cs
示例8: SetConvexRadius
private void SetConvexRadius(HkdBreakableShape bShape, float radius)
{
var sh = bShape.GetShape();
if (sh.IsConvex)
{
var convex = (HkConvexShape)sh;
if(convex.ConvexRadius > radius)
convex.ConvexRadius = radius;
return;
}
if (sh.IsContainer())
{
HkShapeContainerIterator container = sh.GetContainer();
while (container.IsValid)
{
if (container.CurrentValue.IsConvex)
{
var convex = (HkConvexShape)container.CurrentValue;
if (convex.ConvexRadius > radius)
convex.ConvexRadius = radius;
}
container.Next();
}
}
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:25,代码来源:MyDestructionData.cs
示例9: DisableRefCountRec
private void DisableRefCountRec(HkdBreakableShape bShape)
{
bShape.DisableRefCount();
var lst = new List<HkdShapeInstanceInfo>();
bShape.GetChildren(lst);
foreach (var child in lst)
DisableRefCountRec(child.Shape);
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:8,代码来源:MyDestructionData.cs
示例10: Init
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
{
base.Init(builder, cubeGrid);
ProfilerShort.Begin("FP.Init");
CheckConnectionAllowed = true;
var ob = builder as MyObjectBuilder_FracturedBlock;
if (ob.Shapes.Count == 0)
{
ProfilerShort.End();
return;
}
OriginalBlocks = new List<MyDefinitionId>();
Orientations = new List<MyBlockOrientation>();
var lst = new List<HkdShapeInstanceInfo>();
foreach (var def in ob.BlockDefinitions)
{
var blockDef = MyDefinitionManager.Static.GetCubeBlockDefinition(def);
if (MyModels.GetModelOnlyData(blockDef.Model).HavokBreakableShapes == null)
{
MyDestructionData.Static.LoadModelDestruction(blockDef, false, Vector3.One);
}
var shape = MyModels.GetModelOnlyData(blockDef.Model).HavokBreakableShapes[0];
var si = new HkdShapeInstanceInfo(shape, null, null);
lst.Add(si);
m_children.Add(si);
shape.GetChildren(m_children);
OriginalBlocks.Add(def);
}
foreach (var or in ob.BlockOrientations)
{
Orientations.Add(or);
}
m_shapes.AddRange(ob.Shapes);
for (int i = 0; i < m_children.Count; i++)
{
var child = m_children[i];
Func<MyObjectBuilder_FracturedBlock.ShapeB, bool> x = s => s.Name == child.ShapeName;
var result = m_shapes.Where(x);
if (result.Count() > 0)
{
var found = result.First();
var m = Matrix.CreateFromQuaternion(found.Orientation);
m.Translation = child.GetTransform().Translation;
var si = new HkdShapeInstanceInfo(child.Shape.Clone(), m);
if(found.Fixed)
si.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
lst.Add(si);
m_shapeInfos.Add(si);
m_shapes.Remove(found);
}
else
{
child.GetChildren(m_children);
}
}
if (m_shapeInfos.Count == 0)
{
m_children.Clear();
ProfilerShort.End();
Debug.Fail("No relevant shape was found for fractured block. It was probably reexported and names changed.");
throw new Exception("No relevant shape was found for fractured block. It was probably reexported and names changed.");
}
foreach (var shape in m_shapeInfos)
{
if(! string.IsNullOrEmpty(shape.Shape.Name))
Render.AddPiece(shape.Shape.Name, Matrix.CreateFromQuaternion(Quaternion.CreateFromRotationMatrix(shape.GetTransform().GetOrientation())));
}
if (CubeGrid.CreatePhysics)
{
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, m_shapeInfos);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
Shape = compound;
var mp = new HkMassProperties();
compound.BuildMassProperties(ref mp);
Shape = new HkdBreakableShape(compound.GetShape(), ref mp);
compound.RemoveReference();
foreach (var si in m_shapeInfos)
{
var siRef = si;
Shape.AddShape(ref siRef);
}
Shape.SetStrenght(MyDestructionConstants.STRENGTH);
CreateMountPoints();
}
m_children.Clear();
foreach (var si in m_shapeInfos)
si.Shape.RemoveReference();
foreach (var si in lst)
si.RemoveReference();
m_shapeInfos.Clear();
ProfilerShort.End();
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:97,代码来源:MyFracturedBlock.cs
示例11: IsBreakableShapeCompound
private static bool IsBreakableShapeCompound(HkdBreakableShape shape)
{
return (string.IsNullOrEmpty(shape.Name) || shape.IsCompound() || shape.GetChildrenCount() > 0);
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:4,代码来源:MyGridPhysics.Destruction.cs
示例12: SetDataFromHavok
internal void SetDataFromHavok(HkdBreakableShape shape, bool compound)
{
Shape = shape;
if (compound)
{
SetDataFromCompound(shape);
}
else
{
var render = this.Render as MyRenderComponentFracturedPiece;
render.AddPiece(shape.Name, Matrix.Identity);
}
CreateMountPoints();
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:14,代码来源:MyFracturedBlock.cs
示例13: AddMountForShape
private HkdBreakableShape AddMountForShape(HkdBreakableShape shape, Matrix transform, ref BoundingBox blockBB)
{
Vector4 min;
Vector4 max;
shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix);
var bb = new BoundingBox(new Vector3(min), new Vector3(max));
bb = bb.Transform(transform);
bb.Min /= CubeGrid.GridSize; //normalize for mount point
bb.Max /= CubeGrid.GridSize;
bb.Inflate(0.04f);//add tolerance (fracture shapes are smaller than block)
bb.Min += blockBB.HalfExtents;
bb.Max += blockBB.HalfExtents;
if (blockBB.Contains(bb) == ContainmentType.Intersects)
{
bb.Inflate(-0.04f);
foreach (var directionEnum in Base6Directions.EnumDirections)
{
int dirEnum = (int)directionEnum;
Vector3 direction = Base6Directions.Directions[dirEnum];
Vector3 absDir = Vector3.Abs(direction);
var mp = new MyCubeBlockDefinition.MountPoint();
mp.Start = bb.Min;
mp.End = bb.Max;
var start = mp.Start * absDir / (blockBB.HalfExtents * 2) - absDir * 0.04f;
var end = mp.End * absDir / (blockBB.HalfExtents * 2) + absDir * 0.04f;
bool add = false;
bool one = false;
if (start.Max() < 1 && end.Max() > 1 && direction.Max() > 0)
{
add = true;
one = true;
}
else if (start.Min() < 0 && end.Max() > 0 && direction.Min() < 0)
{
add = true;
}
if (!add)
{
continue;
}
mp.Start -= mp.Start * absDir - absDir * 0.04f;
mp.End -= mp.End * absDir + absDir * 0.04f;
if (one)
{
mp.Start += absDir * blockBB.HalfExtents * 2;
mp.End += absDir * blockBB.HalfExtents * 2;
}
mp.Start -= blockBB.HalfExtents - Vector3.One / 2;
mp.End -= blockBB.HalfExtents - Vector3.One / 2;
mp.Normal = new Vector3I(direction);
MountPoints.Add(mp);
}
}
return shape;
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:57,代码来源:MyFracturedBlock.cs
示例14: SetDataFromCompound
public void SetDataFromCompound(HkdBreakableShape compound)
{
var render = this.Render as MyRenderComponentFracturedPiece;
if (render != null)
{
compound.GetChildren(m_shapeInfos);
foreach (var shapeInstanceInfo in m_shapeInfos)
{
System.Diagnostics.Debug.Assert(shapeInstanceInfo.IsValid(), "Invalid shapeInstanceInfo!");
if (shapeInstanceInfo.IsValid())
{
render.AddPiece(shapeInstanceInfo.ShapeName, shapeInstanceInfo.GetTransform());
}
}
m_shapeInfos.Clear();
}
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:20,代码来源:MyFracturedBlock.cs
示例15: ConvertAllShapesToFractureComponentShapeBuilder
private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation, HashSet<string> names, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder)
{
var name = shape.Name;
if (names.Contains(name))
{
MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
if (shapeOrientation == blockOrientation)
{
MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
builderShape.Name = name;
builderShape.Fixed = MyDestructionHelper.IsFixed(shape);
fractureComponentBuilder.Shapes.Add(builderShape);
}
}
if (shape.GetChildrenCount() > 0)
{
List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
shape.GetChildren(children);
foreach (var child in children)
{
var childShapeRotation = child.GetTransform();
ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, names, fractureComponentBuilder);
}
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:28,代码来源:MyFracturedBlock.cs
示例16: GetAllBlockBreakableShapeNames
private static void GetAllBlockBreakableShapeNames(HkdBreakableShape shape, HashSet<string> outNames)
{
var name = shape.Name;
if (!string.IsNullOrEmpty(name))
outNames.Add(name);
if (shape.GetChildrenCount() > 0)
{
List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
shape.GetChildren(children);
foreach (var child in children)
GetAllBlockBreakableShapeNames(child.Shape, outNames);
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:14,代码来源:MyFracturedBlock.cs
示例17: FractureBreakableShape
void FractureBreakableShape(HkdBreakableShape bShape, MyModelFractures modelFractures, string modPath)
{
HkdFracture fracture = null;
HkReferenceObject geometry = null;
if (modelFractures.Fractures[0] is RandomSplitFractureSettings)
{
var settings = (RandomSplitFractureSettings)modelFractures.Fractures[0];
fracture = new HkdRandomSplitFracture()
{
NumObjectsOnLevel1 = settings.NumObjectsOnLevel1,
NumObjectsOnLevel2 = settings.NumObjectsOnLevel2,
RandomRange = settings.RandomRange,
RandomSeed1 = settings.RandomSeed1,
RandomSeed2 = settings.RandomSeed2,
SplitGeometryScale = Vector4.One
};
if (!string.IsNullOrEmpty(settings.SplitPlane))
{
var splitPlane = settings.SplitPlane;
if (!string.IsNullOrEmpty(modPath))
splitPlane = Path.Combine(modPath, settings.SplitPlane);
geometry = CreateGeometryFromSplitPlane(splitPlane);
if (geometry != null)
{
((HkdRandomSplitFracture)fracture).SetGeometry(geometry);
VRageRender.MyRenderProxy.PreloadMaterials(splitPlane);
}
}
}
if (modelFractures.Fractures[0] is VoronoiFractureSettings)
{
var settings = (VoronoiFractureSettings)modelFractures.Fractures[0];
fracture = new HkdVoronoiFracture()
{
Seed = settings.Seed,
NumSitesToGenerate = settings.NumSitesToGenerate,
NumIterations = settings.NumIterations
};
if (!string.IsNullOrEmpty(settings.SplitPlane))
{
var splitPlane = settings.SplitPlane;
if (!string.IsNullOrEmpty(modPath))
splitPlane = Path.Combine(modPath, settings.SplitPlane);
geometry = CreateGeometryFromSplitPlane(splitPlane);
var pspm = MyModels.GetModel(splitPlane);
if (geometry != null)
{
((HkdVoronoiFracture)fracture).SetGeometry(geometry);
VRageRender.MyRenderProxy.PreloadMaterials(splitPlane);
}
}
}
if (modelFractures.Fractures[0] is WoodFractureSettings)
{
//TODO: Apply wood fracture algorithm
var settings = (WoodFractureSettings)modelFractures.Fractures[0];
fracture = new HkdWoodFracture()
{
//Seed = settings.Seed,
//NumSitesToGenerate = settings.NumSitesToGenerate,
//NumIterations = settings.NumIterations
};
//if (!string.IsNullOrEmpty(settings.SplitPlane))
//{
// var splitPlane = settings.SplitPlane;
// if (!string.IsNullOrEmpty(modPath))
// splitPlane = Path.Combine(modPath, settings.SplitPlane);
// geometry = CreateGeometryFromSplitPlane(splitPlane);
// var pspm = MyModels.GetModel(splitPlane);
// if (geometry != null)
// {
// ((HkdWoodFracture)fracture).SetGeometry(geometry);
// VRageRender.MyRenderProxy.PreloadMaterials(splitPlane);
// }
//}
}
//if (woodButton.IsChecked)
//{
// fracture = new HkdWoodFracture()
// {
// RandomSeed = 123456,
// BoardSplittingData = new HkdWoodFracture.SplittingData()
// {
// },
// SplinterSplittingData = new HkdWoodFracture.SplittingData()
// {
// }
//.........这里部分代码省略.........
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:101,代码来源:MyDestructionData.cs
示例18: CreateBreakableBody
private HkShape CreateBreakableBody(HkShape shape, HkMassProperties? massProperties)
{
ProfilerShort.Begin("CreateGridBody");
HkdBreakableShape breakable;
HkMassProperties massProps = massProperties.HasValue ? massProperties.Value : new HkMassProperties();
if (!Shape.BreakableShape.IsValid())
Shape.CreateBreakableShape();
breakable = Shape.BreakableShape;
if (!breakable.IsValid())
{
breakable = new HkdBreakableShape(shape);
if (massProperties.HasValue)
{
var mp = massProperties.Value;
breakable.SetMassProperties(ref mp);
}
else
breakable.SetMassRecursively(50);
}
else
breakable.BuildMassProperties(ref massProps);
shape = breakable.GetShape(); //doesnt add reference
HkRigidBodyCinfo rbInfo = new HkRigidBodyCinfo();
rbInfo.AngularDamping = m_angularDamping;
rbInfo.LinearDamping = m_linearDamping;
rbInfo.SolverDeactivation = m_grid.IsStatic ? InitialSolverDeactivation : HkSolverDeactivation.Low;
rbInfo.ContactPointCallbackDelay = ContactPointDelay;
rbInfo.Shape = shape;
rbInfo.SetMassProperties(massProps);
//rbInfo.Position = Entity.PositionComp.GetPosition(); //obsolete with large worlds?
GetInfoFromFlags(rbInfo, Flags);
if (m_grid.IsStatic)
{
rbInfo.MotionType = HkMotionType.Dynamic;
rbInfo.QualityType = HkCollidableQualityType.Moving;
}
HkRigidBody rb = new HkRigidBody(rbInfo);
if (m_grid.IsStatic)
{
rb.UpdateMotionType(HkMotionType.Fixed);
}
rb.EnableDeactivation = true;
BreakableBody = new HkdBreakableBody(breakable, rb, null, Matrix.Identity);
//DestructionBody.ConnectToWorld(HavokWorld, 0.05f);
BreakableBody.AfterReplaceBody += FracturedBody_AfterReplaceBody;
//RigidBody.SetWorldMatrix(Entity.PositionComp.WorldMatrix);
//breakable.Dispose();
ProfilerShort.End();
return shape;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:58,代码来源:MyGridPhysics.Destruction.cs
示例19: CreateBreakableShapeFromCollisionShapes
void CreateBreakableShapeFromCollisionShapes(MyModel model, Vector3 defaultSize, MyPhysicalModelDefinition modelDef)
{
// Make box half edge length of the grid so fractured block is smaller than not fractured, also good for compounds
HkShape shape;
if (model.HavokCollisionShapes != null && model.HavokCollisionShapes.Length > 0)
{
if (model.HavokCollisionShapes.Length > 1)
{
shape = HkListShape.Create(model.HavokCollisionShapes, model.HavokCollisionShapes.Length, HkReferencePolicy.None);
}
else
{
shape = model.HavokCollisionShapes[0];
shape.AddReference();
}
}
else
{
//modelDef.Size * (modelDef.CubeSize == MyCubeSize.Large ? 2.5f : 0.25f)
shape = new HkBoxShape(defaultSize * 0.5f, MyPerGameSettings.PhysicsConvexRadius);
}
var boxBreakable = new HkdBreakableShape(shape);
boxBreakable.Name = model.AssetName;
boxBreakable.SetMass(modelDef.Mass);
model.HavokBreakableShapes = new HkdBreakableShape[] { boxBreakable };
shape.RemoveReference();
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:28,代码来源:MyDestructionData.cs
示例20: FindFracturedBlocks
private void FindFracturedBlocks(HkdBreakableBodyInfo b)
{
ProfilerShort.Begin("DBHelper");
var dbHelper = new HkdBreakableBodyHelper(b);
ProfilerShort.BeginNextBlock("GetRBMatrix");
var bodyMatrix = dbHelper.GetRigidBodyMatrix();
ProfilerShort.BeginNextBlock("SearchChildren");
dbHelper.GetChildren(m_children);
foreach (var child in m_children)
{
if (!child.IsFracturePiece())
continue;
//var blockPosWorld = ClusterToWorld(Vector3.Transform(child.GetTransform().Translation, bodyMatrix));
var bShape = child.Shape;
HkVec3IProperty pProp = bShape.GetProperty(HkdBreakableShape.PROPERTY_GRID_POSITION);
var blockPos = pProp.Value; //Vector3I.Round(child.GetTransform().Translation / m_grid.GridSize);
if (!m_grid.CubeExists(blockPos))
{
//Debug.Fail("FindFracturedBlocks:Fracture piece missing block");//safe to ignore
continue;
}
if (MyFakes.ENABLE_FRACTURE_COMPONENT)
{
var block = m_grid.GetCubeBlock(blockPos);
if (block == null)
continue;
if (!FindFractureComponentBlocks(block, child))
continue;
}
else
{
if (!m_fracturedBlocksShapes.ContainsKey(blockPos))
m_fracturedBlocksShapes[blockPos] = new List<HkdShapeInstanceInfo>();
m_fracturedBlocksShapes[blockPos].Add(child);
}
}
ProfilerShort.BeginNextBlock("CreateFreacturedBlocks");
if (!MyFakes.ENABLE_FRACTURE_COMPONENT)
{
foreach (var key in m_fracturedBlocksShapes.Keys)
{
HkdBreakableShape shape;
var shapeList = m_fracturedBlocksShapes[key];
foreach (var s in shapeList)
{
var matrix = s.GetTransform();
matrix.Translation = Vector3.Zero;
s.SetTransform(ref matrix);
}
ProfilerShort.Begin("CreateShape");
HkdBreakableShape compound = new HkdCompoundBreakableShape(null, shapeList);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
var mp = new HkMassProperties();
compound.BuildMassProperties(ref mp);
shape = compound;
var sh = compound.GetShape();
shape = new HkdBreakableShape(sh, ref mp);
//shape.SetMassProperties(mp); //important! pass mp to constructor
foreach (var si in shapeList)
{
var siRef = si;
shape.AddShape(ref siRef);
}
compound.RemoveReference();
ProfilerShort.BeginNextBlock("Connect");
//shape.SetChildrenParent(shape);
ConnectPiecesInBlock(shape, shapeList);
ProfilerShort.End();
var info = new MyFracturedBlock.Info()
{
Shape = shape,
Position = key,
Compound = true,
};
var originalBlock = m_grid.GetCubeBlock(key);
if (originalBlock == null)
{
//Debug.Fail("Missing fracture piece original block.");//safe to ignore
shape.RemoveReference();
continue;
}
Debug.Assert(originalBlock != null);
if (originalBlock.FatBlock is MyFracturedBlock)
{
var fractured = originalBlock.FatBlock as MyFracturedBlock;
info.OriginalBlocks = fractured.OriginalBlocks;
info.Orientations = fractured.Orientations;
info.MultiBlocks = fractured.MultiBlocks;
}
else if (originalBlock.FatBlock is MyCompoundCubeBlock)
{
info.OriginalBlocks = new List<MyDefinitionId>();
info.Orientations = new List<MyBlockOrientation>();
MyCompoundCubeBlock compoundBlock = originalBlock.FatBlock as MyCompoundCubeBlock;
bool hasMultiBlockPart = false;
var blocksInCompound = compoundBlock.GetBlocks();
foreach (var block in blocksInCompound)
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridPhysics.Destruction.cs
注:本文中的HkdBreakableShape类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论