public MyEditorActionVoxelHand(MyVoxelMap voxelMap, MyVoxelHandShape voxelHandShape) : base(voxelMap) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyEditorActionVoxelHand::ctor"); m_voxelHandShape = voxelHandShape; m_voxelShapes = voxelMap.GetVoxelHandShapes(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }
public static void LoadData() { // default shape is sphere MyMwcObjectBuilder_VoxelHand_Sphere defaultBuilder = new MyMwcObjectBuilder_VoxelHand_Sphere(new MyMwcPositionAndOrientation(MySpectator.Orientation, Vector3.Forward, Vector3.Up), MyVoxelConstants.DEFAULT_VOXEL_HAND_SIZE, MyMwcVoxelHandModeTypeEnum.SUBTRACT); VoxelHandShape = new MyVoxelHandSphere(); ((MyVoxelHandSphere)VoxelHandShape).Init(defaultBuilder, null); m_Enabled = false; m_timeFromLastShaping = 0; m_distance = MyVoxelConstants.DEFAULT_VOXEL_HAND_DISTANCE; IsProjected = false; IsProjectedToWaypoints = false; }
public static void SetVoxelProperties(MyVoxelHandShapeType voxelHandShapeType, float distance, MyMwcVoxelHandModeTypeEnum modeType, MyMwcVoxelMaterialsEnum?materialEnum, bool isProjected, bool isProjectedToWaypoints) { IsProjected = isProjected; IsProjectedToWaypoints = isProjectedToWaypoints; // same shape type if (voxelHandShapeType == MyEditorVoxelHand.VoxelHandShape.GetShapeType()) { //if ((size >= MyVoxelConstants.MIN_VOXEL_HAND_SIZE) && (size <= MyVoxelConstants.MAX_VOXEL_HAND_SIZE)) { //MyEditorVoxelHand.VoxelHandShape.SetShapeSize(size); //MyEditorVoxelHand.VoxelHandShape.SetShapeSize2(size2); //MyEditorVoxelHand.VoxelHandShape.SetShapeSize3(size3); MyEditorVoxelHand.VoxelHandShape.ModeType = modeType; MyEditorVoxelHand.VoxelHandShape.Material = materialEnum; } } // another shape type else { // float newShapeSize = size; // if ((newShapeSize < MyVoxelConstants.MIN_VOXEL_HAND_SIZE) && (newShapeSize > MyVoxelConstants.MAX_VOXEL_HAND_SIZE)) float newShapeSize = MyVoxelConstants.DEFAULT_VOXEL_HAND_SIZE; MyMwcPositionAndOrientation positionAndOritentation = new MyMwcPositionAndOrientation(MySpectator.Position, Vector3.Forward, Vector3.Up); switch (voxelHandShapeType) { case MyVoxelHandShapeType.Sphere: MyMwcObjectBuilder_VoxelHand_Sphere sphereObjectBuilder = new MyMwcObjectBuilder_VoxelHand_Sphere(positionAndOritentation, newShapeSize, modeType); MyEditorVoxelHand.VoxelHandShape = new MyVoxelHandSphere(); ((MyVoxelHandSphere)MyEditorVoxelHand.VoxelHandShape).Init(sphereObjectBuilder, null); break; case MyVoxelHandShapeType.Box: MyMwcObjectBuilder_VoxelHand_Box boxObjectBuilder = new MyMwcObjectBuilder_VoxelHand_Box(positionAndOritentation, newShapeSize, modeType); MyEditorVoxelHand.VoxelHandShape = new MyVoxelHandBox(); ((MyVoxelHandBox)MyEditorVoxelHand.VoxelHandShape).Init(boxObjectBuilder, null); break; case MyVoxelHandShapeType.Cuboid: MyMwcObjectBuilder_VoxelHand_Cuboid cuboidObjectBuilder = new MyMwcObjectBuilder_VoxelHand_Cuboid(positionAndOritentation, newShapeSize, newShapeSize, newShapeSize, newShapeSize, newShapeSize, modeType); MyEditorVoxelHand.VoxelHandShape = new MyVoxelHandCuboid(); ((MyVoxelHandCuboid)MyEditorVoxelHand.VoxelHandShape).Init(cuboidObjectBuilder, null); break; case MyVoxelHandShapeType.Cylinder: MyMwcObjectBuilder_VoxelHand_Cylinder cylinderObjectBuilder = new MyMwcObjectBuilder_VoxelHand_Cylinder(positionAndOritentation, newShapeSize, newShapeSize, newShapeSize, modeType); MyEditorVoxelHand.VoxelHandShape = new MyVoxelHandCylinder(); ((MyVoxelHandCylinder)MyEditorVoxelHand.VoxelHandShape).Init(cylinderObjectBuilder, null); break; default: System.Diagnostics.Debug.Assert(false); break; } MyEditorVoxelHand.VoxelHandShape.Material = materialEnum; } if (IsProjected) { if (!MyFakes.MWBUILDER) { if ((distance >= MyVoxelConstants.MIN_PROJECTED_VOXEL_HAND_OFFSET) && (distance <= MyVoxelConstants.MAX_PROJECTED_VOXEL_HAND_OFFSET)) { MyEditorVoxelHand.SetShapeDistance(distance); } } } else if (IsProjectedToWaypoints) { } else { if ((distance >= MyVoxelConstants.MIN_VOXEL_HAND_DISTANCE) && (distance <= MyVoxelConstants.MAX_VOXEL_HAND_DISTANCE)) { MyEditorVoxelHand.SetShapeDistance(distance); } } MyEditorVoxelHand.UpdateShapePosition(); }
/// <summary> /// Applies voxel hand shape to this voxel map /// </summary> /// <param name="voxelHandShape"></param> public void AddVoxelHandShape(MyVoxelHandShape voxelHandShape, bool playSounds) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("AddVoxelHandShape"); if (MyVoxelMaps.GetVoxelShapesCount() + 1 <= MyVoxelConstants.MAX_VOXEL_HAND_SHAPES_COUNT) { bool changed = false; MyMwcVoxelHandModeTypeEnum voxelHandModeType = voxelHandShape.ModeType; // sphere if (voxelHandShape is MyVoxelHandSphere) { MyVoxelHandShape voxelHandSphere = (MyVoxelHandShape)voxelHandShape; BoundingSphere bSphere = voxelHandSphere.WorldVolume; if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SUBTRACT) { MyVoxelGenerator.CutOutSphereInvalidateCache(this, bSphere, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandRemove); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.ADD) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("CreateSphereInvalidateCache"); MyVoxelGenerator.CreateSphereInvalidateCache(this, bSphere, ref changed, voxelHandShape.Material); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyAudio.AddCue2D"); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandAdd); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SET_MATERIAL) { SetVoxelMaterialInvalidateCache(voxelHandShape.Material.Value, bSphere, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandMaterial); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SOFTEN) { SoftenVoxelContentInSphereInvalidateCache(bSphere, MyVoxelConstants.DEFAULT_SOFTEN_WEIGHT, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.WRINKLE) { WrinkleVoxelContentInSphereInvalidateCache(bSphere, MyVoxelConstants.DEFAULT_WRINKLE_WEIGHT_ADD, MyVoxelConstants.DEFAULT_WRINKLE_WEIGHT_REMOVE, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } } // box else if (voxelHandShape is MyVoxelHandBox) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("VoxelHand MyVoxelHandBox"); MyVoxelHandBox voxelHandBox = (MyVoxelHandBox)voxelHandShape; //BoundingBox bBox = voxelHandBox.GetLocalBoundingBox(); //Matrix world = Matrix.CreateWorld(voxelHandBox.GetPosition(), this.WorldMatrix.Forward, this.WorldMatrix.Up); Matrix world = voxelHandBox.WorldMatrix; //bBox = bBox.Transform(world); //MyModel model = MyModels.GetModelForDraw(MyModelsEnum.ExplosionDebrisVoxel); //MyModel model = MyMinerGameDX.Static.Content.Load<MyModel>("Box"); List<Vector3> vertexes = new List<Vector3>(); List<MyTriangleVertexIndices> triangles = new List<MyTriangleVertexIndices>(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GenerateBoxVerticesAndTriangles"); GenerateBoxVerticesAndTriangles(ref vertexes, ref triangles, voxelHandBox.Size, voxelHandBox.Size); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SUBTRACT) { //MyVoxelGenerator.CutOutBoxInvalidateCache(this, bBox, ref originalContents); //MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.RemoveVoxels, world, voxelHandShape.Material, ref changed); MyOrientedBoundingBox box = MyOrientedBoundingBox.Create(voxelHandBox.GetLocalBoundingBox(), voxelHandBox.WorldMatrix); MyVoxelGenerator.CutOutOrientedBox(this, box, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandRemove); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.ADD) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMwcVoxelHandModeTypeEnum.ADD"); //MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.AddVoxels, world, voxelHandShape.Material, ref changed); MyOrientedBoundingBox box = MyOrientedBoundingBox.Create(voxelHandBox.GetLocalBoundingBox(), voxelHandBox.WorldMatrix); MyVoxelGenerator.CreateOrientedBox(this, box, voxelHandShape.Material); changed = true; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); //MyVoxelGenerator.CreateBoxInvalidateCache(this, bBox, ref originalContents); //if (voxelHandShape.Material != null) //{ // SetVoxelMaterialInvalidateCache(voxelHandShape.Material.Value, bBox, ref originalContents); //} if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandAdd); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SET_MATERIAL) { //SetVoxelMaterialInvalidateCache(voxelHandShape.Material.Value, bBox, ref originalContents); MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.ChangeMaterial, world, voxelHandShape.Material, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandMaterial); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SOFTEN) { //SoftenVoxelContentInBoxInvalidateCache(bBox, MyVoxelConstants.DEFAULT_SOFTEN_WEIGHT, ref originalContents); MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.SoftenVoxels, world, voxelHandShape.Material, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.WRINKLE) { //SoftenVoxelContentInBoxInvalidateCache(bBox, MyVoxelConstants.DEFAULT_WRINKLE_WEIGHT, ref originalContents); MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.WrinkleVoxels, world, voxelHandShape.Material, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } // cuboid else if (voxelHandShape is MyVoxelHandCuboid) { MyVoxelHandCuboid voxelHandCuboid = (MyVoxelHandCuboid)voxelHandShape; Matrix world = voxelHandCuboid.WorldMatrix; if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SUBTRACT) { MyVoxelGenerator.CutOutCuboid(this, voxelHandCuboid.Cuboid.CreateTransformed(ref world), voxelHandShape.Material); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandRemove); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.ADD) { MyVoxelGenerator.CreateCuboid(this, voxelHandCuboid.Cuboid.CreateTransformed(ref world), voxelHandShape.Material); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandAdd); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SET_MATERIAL) { // MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.ChangeMaterial, world, voxelHandShape.Material, ref changed); //SetVoxelMaterialInvalidateCache(voxelHandShape.Material.Value, bBox, ref originalContents); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandMaterial); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SOFTEN) { //MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.SoftenVoxels, world, voxelHandShape.Material, ref changed); //SoftenVoxelContentInBoxInvalidateCache(bBox, MyVoxelConstants.DEFAULT_SOFTEN_WEIGHT, ref originalContents); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.WRINKLE) { //MyVoxelImport.Run(this, vertexes.ToArray(), triangles.ToArray(), MyvoxelImportAction.WrinkleVoxels, world, voxelHandShape.Material, ref changed); //SoftenVoxelContentInBoxInvalidateCache(bBox, MyVoxelConstants.DEFAULT_WRINKLE_WEIGHT, ref originalContents); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandSoften); } } else if (voxelHandShape is MyVoxelHandCylinder) { MyVoxelHandCylinder voxelHandCylinder = (MyVoxelHandCylinder)voxelHandShape; MyOrientedBoundingBox box = MyOrientedBoundingBox.Create(voxelHandCylinder.GetLocalBoundingBox(), voxelHandCylinder.WorldMatrix); if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.SUBTRACT) { MyVoxelGenerator.CutOutCylinder(this, voxelHandCylinder.Radius1, voxelHandCylinder.Radius2, box, voxelHandShape.Material, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandRemove); } else if (voxelHandModeType == MyMwcVoxelHandModeTypeEnum.ADD) { MyVoxelGenerator.CreateCylinder(this, voxelHandCylinder.Radius1, voxelHandCylinder.Radius2, box, voxelHandShape.Material, ref changed); if (playSounds) MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorVoxelHandAdd); } } else System.Diagnostics.Debug.Assert(false); // adds only if there are any changes if (changed == true) { this.AddChild(voxelHandShape, true); m_voxelHandShapes.Add(voxelHandShape); if (OnVoxelHandShapeCountChange != null) { OnVoxelHandShapeCountChange(1); } CalcAverageDataCellMaterials(); } } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }