本文整理汇总了C#中HkdBreakableShape类的典型用法代码示例。如果您正苦于以下问题:C# HkdBreakableShape类的具体用法?C# HkdBreakableShape怎么用?C# HkdBreakableShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HkdBreakableShape类属于命名空间,在下文中一共展示了HkdBreakableShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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--;
}
示例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;
}
示例4: DontCreateFracture
private static bool DontCreateFracture(HkdBreakableShape breakableShape)
{
if (!breakableShape.IsValid())
return false;
return (breakableShape.UserObject & (uint)HkdBreakableShape.Flags.DONT_CREATE_FRACTURE_PIECE) != 0;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
}
示例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);
}
示例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();
}
示例11: IsBreakableShapeCompound
private static bool IsBreakableShapeCompound(HkdBreakableShape shape)
{
return (string.IsNullOrEmpty(shape.Name) || shape.IsCompound() || shape.GetChildrenCount() > 0);
}
示例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();
}
示例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;
}
示例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();
}
}
示例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);
}
}
}