public void AppendModelMeshPart(ModelMeshPart meshPart, Matrix matrix, bool makeEmissive, bool flipWindingOrder, bool doubleSided, bool flipNormals, Color color) { VertexBuffer vertexBuffer = meshPart.VertexBuffer; IndexBuffer indexBuffer = meshPart.IndexBuffer; ReadOnlyList <VertexElement> vertexElements = vertexBuffer.VertexDeclaration.VertexElements; if (vertexElements.Count != 3 || vertexElements[0].Offset != 0 || vertexElements[0].Semantic != VertexElementSemantic.Position.GetSemanticString() || vertexElements[1].Offset != 12 || vertexElements[1].Semantic != VertexElementSemantic.Normal.GetSemanticString() || vertexElements[2].Offset != 24 || vertexElements[2].Semantic != VertexElementSemantic.TextureCoordinate.GetSemanticString()) { throw new InvalidOperationException("Wrong vertex format for a block mesh."); } publicVertex[] vertexData = GetVertexData <publicVertex>(vertexBuffer); ushort[] indexData = GetIndexData <ushort>(indexBuffer); Dictionary <ushort, ushort> dictionary = new Dictionary <ushort, ushort>(); for (int i = meshPart.StartIndex; i < meshPart.StartIndex + meshPart.IndicesCount; i++) { ushort num = indexData[i]; if (!dictionary.ContainsKey(num)) { dictionary.Add(num, (ushort)Vertices.Count); BlockMeshVertex item = default(BlockMeshVertex); item.Position = Vector3.Transform(vertexData[num].Position, matrix); item.TextureCoordinates = vertexData[num].TextureCoordinate; Vector3 vector = Vector3.Normalize(Vector3.TransformNormal(flipNormals ? (-vertexData[num].Normal) : vertexData[num].Normal, matrix)); if (makeEmissive) { item.IsEmissive = true; item.Color = color; } else { item.Color = color * LightingManager.CalculateLighting(vector); item.Color.A = color.A; } item.Face = (byte)CellFace.Vector3ToFace(vector); Vertices.Add(item); } } for (int j = 0; j < meshPart.IndicesCount / 3; j++) { if (doubleSided) { Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]); } else if (flipWindingOrder) { Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]); } else { Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]); Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]); } } Trim(); }
public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner) { FurnitureDesign design = null; FurnitureDesign furnitureDesign = null; Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>(); Point3 point = start.Point; Point3 point2 = start.Point; int startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z); int num = Terrain.ExtractContents(startValue); if (BlocksManager.Blocks[num] is FurnitureBlock) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue)); furnitureDesign = GetDesign(designIndex); if (furnitureDesign == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } design = furnitureDesign.Clone(); design.LinkedDesign = null; design.InteractionMode = FurnitureInteractionMode.None; valuesDictionary.Add(start.Point, startValue); } else { Stack <Point3> val = new Stack <Point3>(); val.Push(start.Point); while (val.Count > 0) { Point3 key = val.Pop(); if (valuesDictionary.ContainsKey(key)) { continue; } int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z); if (IsValueDisallowed(cellValue)) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } if (IsValueAllowed(cellValue)) { if (key.X < point.X) { point.X = key.X; } if (key.Y < point.Y) { point.Y = key.Y; } if (key.Z < point.Z) { point.Z = key.Z; } if (key.X > point2.X) { point2.X = key.X; } if (key.Y > point2.Y) { point2.Y = key.Y; } if (key.Z > point2.Z) { point2.Z = key.Z; } if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false); return; } valuesDictionary[key] = cellValue; val.Push(new Point3(key.X - 1, key.Y, key.Z)); val.Push(new Point3(key.X + 1, key.Y, key.Z)); val.Push(new Point3(key.X, key.Y - 1, key.Z)); val.Push(new Point3(key.X, key.Y + 1, key.Z)); val.Push(new Point3(key.X, key.Y, key.Z - 1)); val.Push(new Point3(key.X, key.Y, key.Z + 1)); } } if (valuesDictionary.Count == 0) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false); return; } design = new FurnitureDesign(base.SubsystemTerrain); Point3 point3 = point2 - point; int num2 = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2); int[] array = new int[num2 * num2 * num2]; foreach (KeyValuePair <Point3, int> item in valuesDictionary) { Point3 point4 = item.Key - point; array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value; } design.SetValues(num2, array); int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face); design.Rotate(1, steps); Point3 location = design.Box.Location; Point3 point5 = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size); Point3 delta = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2); design.Shift(delta); } BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result) { if (result) { design = TryAddDesign(design); if (design == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false); } else { if (m_subsystemGameInfo.WorldSettings.GameMode != 0) { foreach (KeyValuePair <Point3, int> item2 in valuesDictionary) { base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true); } } int value = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter)); int num3 = MathUtils.Clamp(design.Resolution, 4, 8); Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix; Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY; m_subsystemPickables.AddPickable(value, num3, position, null, null); componentMiner.DamageActiveTool(1); componentMiner.Poke(forceRestart: false); for (int i = 0; i < 3; i++) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate { m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f); }); } if (componentMiner.ComponentCreature.PlayerStats != null) { componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3; } } } }); if (componentMiner.ComponentPlayer != null) { DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog); } }