本文整理汇总了C#中Sandbox.Definitions.MyVoxelMaterialDefinition类的典型用法代码示例。如果您正苦于以下问题:C# MyVoxelMaterialDefinition类的具体用法?C# MyVoxelMaterialDefinition怎么用?C# MyVoxelMaterialDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyVoxelMaterialDefinition类属于Sandbox.Definitions命名空间,在下文中一共展示了MyVoxelMaterialDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start(Vector3D position, Vector3D initialVelocity, float scale, MyVoxelMaterialDefinition mat)
{
Components.MyRenderComponentDebrisVoxel voxelDebrisRender = Container.Entity.Render as Components.MyRenderComponentDebrisVoxel;
voxelDebrisRender.TexCoordOffset = MyUtils.GetRandomFloat(5, 15);
voxelDebrisRender.TexCoordScale = MyUtils.GetRandomFloat(8, 12);
voxelDebrisRender.VoxelMaterialIndex = mat.Index;
base.Start(position, initialVelocity, scale);
Container.Entity.Render.NeedsResolveCastShadow = true;
Container.Entity.Render.FastCastShadowResolve = true;
}
示例2: MyCompositeOrePlanetDeposit
public MyCompositeOrePlanetDeposit(MyCsgShapeBase baseShape, int seed, float minDepth, float maxDepth, MyOreProbability[] oreProbabilties, MyVoxelMaterialDefinition material) :
base(baseShape, material)
{
m_minDepth = minDepth;
double outherSphereVolume = (4.0 * MathHelper.Pi * Math.Pow(minDepth, 3.0f)) / 3.0;
double innerSphereVolume = (4.0 * MathHelper.Pi * Math.Pow(maxDepth, 3.0f)) / 3.0;
double depositVolume = (4.0 * MathHelper.Pi * Math.Pow(DEPOSIT_MAX_SIZE, 3.0f)) / 3.0;
double volume = outherSphereVolume - innerSphereVolume;
m_numDeposits = oreProbabilties.Length > 0 ? (int)Math.Floor((volume * 0.4f) / depositVolume) : 0;
int numSectors = (int)(minDepth / DEPOSIT_MAX_SIZE);
MyRandom random = MyRandom.Instance;
FillMaterialCollections();
Vector3D offset = -new Vector3D(DEPOSIT_MAX_SIZE/2.0);
using (var stateToken = random.PushSeed(seed))
{
for (int i = 0; i < m_numDeposits; ++i)
{
Vector3D direction = MyProceduralWorldGenerator.GetRandomDirection(random);
float distanceFromCenter = random.NextFloat(maxDepth,minDepth);
Vector3D position = direction * distanceFromCenter;
Vector3I cellPos = Vector3I.Ceiling((Shape.Center() + position)/ DEPOSIT_MAX_SIZE);
MyCompositeShapeOreDeposit deposit;
if (m_deposits.TryGetValue(cellPos, out deposit) == false)
{
var oreDefinition = GetOre(random.NextFloat(0, 1), oreProbabilties);
var materialDefinition = m_materialsByOreType[oreDefinition.OreName][random.Next() % m_materialsByOreType[oreDefinition.OreName].Count];
deposit = new MyCompositeShapeOreDeposit(new MyCsgSimpleSphere(cellPos * DEPOSIT_MAX_SIZE + offset, random.NextFloat(64, DEPOSIT_MAX_SIZE / 2.0f)), materialDefinition);
m_deposits[cellPos] = deposit;
}
}
}
m_materialsByOreType.Clear();
}
示例3: MyCompositeShapeOreDeposit
public MyCompositeShapeOreDeposit(MyCsgShapeBase shape, MyVoxelMaterialDefinition material)
{
System.Diagnostics.Debug.Assert(material != null, "Shape must have material");
Shape = shape;
m_material = material;
}
示例4: CreateVoxelMeteorCrater
public void CreateVoxelMeteorCrater(Vector3D center, float radius, Vector3 normal, MyVoxelMaterialDefinition material)
{
var msg = new MeteorCraterMsg();
msg.EntityId = Entity.EntityId;
msg.Center = center;
msg.Radius = radius;
msg.Normal = normal;
msg.Material = material.Index;
MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
}
示例5: HasMaterial
private bool HasMaterial(MyVoxelMaterialDefinition material)
{
if(material == Material0 || material == Material1 || material == Material2)
{
return true;
}
return false;
}
示例6: OverwriteAllMaterialsInternal
protected abstract void OverwriteAllMaterialsInternal(MyVoxelMaterialDefinition material);
示例7: CreateVoxelMeteorCrater
public void CreateVoxelMeteorCrater(Vector3D center, float radius, Vector3 normal, MyVoxelMaterialDefinition material)
{
BeforeContentChanged = true;
MyMultiplayer.RaiseEvent(RootVoxel, x => x.CreateVoxelMeteorCrater_Implementation, center, radius, normal, material.Index);
}
示例8: EnsureMutable
void IMyStorage.MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
{
EnsureMutable();
m_trueStorage.MergeVoxelMaterials(voxelFile, voxelPosition, materialToSet);
}
示例9: MakeCrater
public static void MakeCrater(MyVoxelBase voxelMap, BoundingSphereD sphere, Vector3 direction, MyVoxelMaterialDefinition material)
{
ProfilerShort.Begin("MakeCrater");
Vector3 normal = Vector3.Normalize(sphere.Center - voxelMap.RootVoxel.WorldMatrix.Translation);
Vector3I minCorner, maxCorner;
{
Vector3D sphereMin = sphere.Center - (sphere.Radius - MyVoxelConstants.VOXEL_SIZE_IN_METRES) * 1.3f;
Vector3D sphereMax = sphere.Center + (sphere.Radius + MyVoxelConstants.VOXEL_SIZE_IN_METRES) * 1.3f;
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);
Vector3I worldMinCorner = minCorner + voxelMap.StorageMin;
Vector3I worldMaxCorner = maxCorner + voxelMap.StorageMin;
// 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 worldMinCorner, ref worldMaxCorner);
ProfilerShort.End();
ProfilerShort.Begin("Changing cache");
int removedVoxelContent = 0;
Vector3I tempVoxelCoord;
Vector3I cachePos = (maxCorner - minCorner) / 2;
byte oldMaterial = m_cache.Material(ref cachePos);
float digRatio = 1 - Vector3.Dot(normal, direction);
Vector3 newCenter = sphere.Center - normal * (float)sphere.Radius * 1.1f;//0.9f;
float sphRadA = (float)(sphere.Radius * 1.5f);
float sphRadSqA = (float)(sphRadA * sphRadA);
float voxelSizeHalfTransformedPosA = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * (2 * sphRadA + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
float voxelSizeHalfTransformedNegA = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * (-2 * sphRadA + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
Vector3 newDelCenter = newCenter + normal * (float)sphere.Radius * (0.7f + digRatio) + direction * (float)sphere.Radius * 0.65f;
float sphRadD = (float)(sphere.Radius);
float sphRadSqD = (float)(sphRadD * sphRadD);
float voxelSizeHalfTransformedPosD = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * (2 * sphRadD + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
float voxelSizeHalfTransformedNegD = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * (-2 * sphRadD + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
Vector3 newSetCenter = newCenter + normal * (float)sphere.Radius * (digRatio) + direction * (float)sphere.Radius * 0.3f;
float sphRadS = (float)(sphere.Radius * 0.1f);
float sphRadSqS = (float)(sphRadS * sphRadS);
float voxelSizeHalfTransformedPosS = MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * (2 * sphRadS + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
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);
byte originalContent = m_cache.Content(ref cachePos);
//Add sphere
if (originalContent != MyVoxelConstants.VOXEL_CONTENT_FULL)
{
float addDist = (float)(voxelPosition - newCenter).LengthSquared();
float addDiff = (float)(addDist - sphRadSqA);
byte newContent;
if (addDiff > voxelSizeHalfTransformedPosA)
{
newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
}
else if (addDiff < voxelSizeHalfTransformedNegA)
{
newContent = MyVoxelConstants.VOXEL_CONTENT_FULL;
}
else
{
float value = (float)Math.Sqrt(addDist + sphRadSqA - 2 * sphRadA * Math.Sqrt(addDist));
if (addDiff < 0) { value = -value; }
// This formula will work even if diff is positive or negative
newContent = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - value / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL);
}
if (newContent > originalContent)
{
if (material != null)
{
m_cache.Material(ref cachePos, oldMaterial);
}
changed = true;
m_cache.Content(ref cachePos, newContent);
}
//.........这里部分代码省略.........
示例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: OverwriteAllMaterialsInternal
protected override void OverwriteAllMaterialsInternal(MyVoxelMaterialDefinition material)
{
Debug.Fail("Not implemented.");
}
示例12: TryHarvestOreMaterial
/// <summary>
/// Converts voxel material to ore material and puts it into the inventory. If there is no
/// corresponding ore for given voxel type, nothing happens.
/// </summary>
private bool TryHarvestOreMaterial(MyVoxelMaterialDefinition material, Vector3 hitPosition, int removedAmount, bool onlyCheck)
{
if (string.IsNullOrEmpty(material.MinedOre))
return false;
//Do one frame heatup only in singleplayer, lag will solve it in multiplayer
if (InitialHeatup())
return true;
if (!onlyCheck)
{
ProfilerShort.Begin("TryHarvestOreMaterial");
var oreObjBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>(material.MinedOre);
float amountCubicMeters = (float)(((float)removedAmount / (float)MyVoxelConstants.VOXEL_CONTENT_FULL) * MyVoxelConstants.VOXEL_VOLUME_IN_METERS * VoxelHarvestRatio);
amountCubicMeters *= (float)material.MinedOreRatio;
if (!MySession.Static.AmountMined.ContainsKey(material.MinedOre))
MySession.Static.AmountMined[material.MinedOre] = 0;
MySession.Static.AmountMined[material.MinedOre] += (MyFixedPoint)amountCubicMeters;
float maxDropCubicMeters = 0.150f;
var physItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(oreObjBuilder);
MyFixedPoint amountInItemCount = (MyFixedPoint)(amountCubicMeters / physItem.Volume);
MyFixedPoint maxAmountPerDrop = (MyFixedPoint)(maxDropCubicMeters / physItem.Volume);
if (OutputInventory != null)
{
MyFixedPoint amountDropped = amountInItemCount * (1 - m_inventoryCollectionRatio);
amountDropped = MyFixedPoint.Min(maxAmountPerDrop * 10 - (MyFixedPoint)0.001, amountDropped);
MyFixedPoint inventoryAmount = (amountInItemCount * m_inventoryCollectionRatio) - amountDropped;
OutputInventory.AddItems(inventoryAmount, oreObjBuilder);
SpawnOrePieces(amountDropped, maxAmountPerDrop, hitPosition, oreObjBuilder, material);
}
else
{
SpawnOrePieces(amountInItemCount, maxAmountPerDrop, hitPosition, oreObjBuilder, material);
}
ProfilerShort.End();
}
return true;
}
示例13: CreateExplosionDebris
public void CreateExplosionDebris(ref BoundingSphereD explosionSphere, float voxelsCountInPercent, MyVoxelMaterialDefinition voxelMaterial, MyVoxelBase voxelMap)
{
MyDebug.AssertDebug((voxelsCountInPercent >= 0.0f) && (voxelsCountInPercent <= 1.0f));
MyDebug.AssertDebug(explosionSphere.Radius > 0);
ProfilerShort.Begin("CreateExplosionDebris");
ProfilerShort.Begin("Matrices");
// This matrix will rotate all newly created debrises, so they won't apper as alligned with coordinate system
MatrixD randomRotationMatrix = MatrixD.CreateRotationX(MyUtils.GetRandomRadian()) *
MatrixD.CreateRotationY(MyUtils.GetRandomRadian());
float highScale = MathHelper.Clamp((float)explosionSphere.Radius * m_debrisScaleUpper, 0, m_debrisScaleClamp);
float lowScale = highScale * (m_debrisScaleLower / m_debrisScaleUpper);
int objectsToGenerate = (int)(m_voxelDebrisOffsets.Count * voxelsCountInPercent);
ProfilerShort.End();
ProfilerShort.Begin("m_positionOffsets");
const float SPHERE_FIT_CUBE_SCALE = 1 / 1.73f; // Resize sphere to fit inside cube
int debrisCount = m_voxelDebrisOffsets.Count;
//float debrisScale = Math.Max(explosionSphere.Radius / debrisCount, 0.2f);
float debrisScale = Math.Max((float)explosionSphere.Radius, 0.2f);
for (int i = 0; i < debrisCount; i++)
{
MyDebrisVoxel newObj = CreateVoxelDebris();
if (newObj == null)
{
break; // no point in continuing
}
Vector3D position = m_voxelDebrisOffsets[i] * (float)explosionSphere.Radius * SPHERE_FIT_CUBE_SCALE;
Vector3D.Transform(ref position, ref randomRotationMatrix, out position);
position += explosionSphere.Center;
var initialVelocity = MyUtils.GetRandomVector3Normalized();
if (initialVelocity == Vector3.Zero)
continue;
initialVelocity *= MyUtils.GetRandomFloat(MyDebrisConstants.EXPLOSION_DEBRIS_INITIAL_SPEED_MIN,
MyDebrisConstants.EXPLOSION_DEBRIS_INITIAL_SPEED_MAX);
(newObj.Debris as MyDebrisVoxel.MyDebrisVoxelLogic).Start(position, initialVelocity, debrisScale, voxelMaterial);
}
ProfilerShort.End();
ProfilerShort.End();
}
示例14: CreateDirectedDebris
public void CreateDirectedDebris(Vector3 sourceWorldPosition,
Vector3 offsetDirection,
float minSourceDistance,
float maxSourceDistance,
float minDeviationAngle,
float maxDeviationAngle,
int debrisPieces,
float initialSpeed,
float scale,
MyVoxelMaterialDefinition material)
{
ProfilerShort.Begin("Create directed debris");
MyDebug.AssertDebug(debrisPieces > 0);
for (int i = 0; i < debrisPieces; ++i)
{
var newObj = CreateVoxelDebris();
if (newObj == null)
{
break; // no point in continuing
}
float dist = MyUtils.GetRandomFloat(minSourceDistance, maxSourceDistance);
float angleX = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
float angleY = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
var rotation = Matrix.CreateRotationX(angleX) * Matrix.CreateRotationY(angleY);
var deviatedDir = Vector3.Transform(offsetDirection, rotation);
var startPos = sourceWorldPosition + deviatedDir * dist;
var initialVelocity = deviatedDir * initialSpeed;
(newObj.Debris as MyDebrisVoxel.MyDebrisVoxelLogic).Start(startPos, initialVelocity, scale, material);
}
ProfilerShort.End();
}
示例15: MyBoxOreDeposit
public MyBoxOreDeposit(MyCsgShapeBase baseShape, MyVoxelMaterialDefinition material) :
base(baseShape, material)
{
m_boxShape = (MyCsgBox)baseShape;
}