public void ReadChunk_SIZE(int byteCount) { m_CurrentModel = new VoxModel(); m_CurrentModel.m_SizeX = m_Reader.ReadInt32(); m_CurrentModel.m_SizeY = m_Reader.ReadInt32(); m_CurrentModel.m_SizeZ = m_Reader.ReadInt32(); }
BakedPointCloud ImportAsBakedPointCloud(string path) { VoxReader voxReader = new VoxReader(); VoxModel model = voxReader.LoadModel(path); if (model == null) { return(null); } List <Vector3> positions = new List <Vector3>(); List <Color> colors = new List <Color>(); var colorsPalette = model.Palette; for (int i = 0; i < model.VoxelFrames.Count; i++) { VoxelData data = model.VoxelFrames[i]; FileToVoxCore.Schematics.Tools.Vector3 worldPositionFrame = model.TransformNodeChunks[i + 1].TranslationAt(); if (worldPositionFrame == FileToVoxCore.Schematics.Tools.Vector3.zero) { continue; } for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int indexColor = data.Get(x, y, z); var color = colorsPalette[indexColor]; if (color != FileToVoxCore.Drawing.Color.Empty) { positions.Add(new Vector3(z + worldPositionFrame.X, y + worldPositionFrame.Z, x + worldPositionFrame.Y)); colors.Add(color.ToUnityColor()); } } } } } BakedPointCloud bakedPointCloud = ScriptableObject.CreateInstance <BakedPointCloud>(); bakedPointCloud.Initialize(positions, colors); bakedPointCloud.name = Path.GetFileNameWithoutExtension(path); return(bakedPointCloud); }
public void ReadChunk_XYZI(int byteCount) { int numVoxels = m_Reader.ReadInt32(); m_CurrentModel.m_Voxels = new VoxPoint[numVoxels]; for (int i = 0; i < numVoxels; ++i) { VoxPoint point = new VoxPoint(); point.x = m_Reader.ReadByte(); point.y = m_Reader.ReadByte(); point.z = m_Reader.ReadByte(); point.colourIndex = m_Reader.ReadByte(); m_CurrentModel.m_Voxels[i] = point; } m_Models.Add(m_CurrentModel); m_CurrentModel = null; }
public VoxToSchematic(string path) : base(path) { VoxReader reader = new VoxReader(); mVoxModel = reader.LoadModel(path); }
static void Main(string[] args) { VoxReader reader = new VoxReader(); VoxWriter writer = new VoxWriter(); DisplayInformations(); if (args.Length < 2) { Console.WriteLine("[ERROR] Missing arguments"); Console.WriteLine("Usage: VoxSlicer.exe SIZE FILE"); return; } try { short size = Convert.ToInt16(args[0]); if (size <= 10 || size > 256) { Console.WriteLine("[ERROR] Size must be between 10 and 256"); return; } VoxModel model = reader.LoadModel(args[1]); if (model == null) { Console.WriteLine("[ERROR] Failed to load model"); return; } Schematic.CHUNK_SIZE = size; DirectoryInfo directory = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[1])); foreach (VoxelData data in model.VoxelFrames) { int sizeX = (int)Math.Ceiling((decimal)data.VoxelsWide / size); int sizeY = (int)Math.Ceiling((decimal)data.VoxelsTall / size); int sizeZ = (int)Math.Ceiling((decimal)data.VoxelsDeep / size); Schematic[,,] schematics = new Schematic[sizeX, sizeY, sizeZ]; Color[] colors = model.Palette; for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int posX = x / size; int posY = y / size; int posZ = z / size; schematics[posX, posY, posZ] ??= new Schematic(); int indexColor = data.Get(x, y, z); Color color = colors[indexColor]; if (indexColor != 0) { schematics[posX, posY, posZ].AddVoxel(x, y, z, color); } } } } for (int x = 0; x < schematics.GetLength(0); x++) { for (int y = 0; y < schematics.GetLength(1); y++) { for (int z = 0; z < schematics.GetLength(2); z++) { if (schematics[x, y, z].GetAllVoxels().Count != 0) { var rotation = model.TransformNodeChunks.First().RotationAt(); string name = $"{Path.GetFileNameWithoutExtension(args[1])}-{x}-{y}-{z}.vox"; Console.WriteLine("[INFO] Started to process: " + name); string outputPath = Path.Combine(directory.FullName, name); writer.WriteModel(size, outputPath, model.Palette.ToList(), schematics[x, y, z], rotation); } } } } } } catch (Exception) { Console.WriteLine("[ERROR] Failed to read voxel volume size"); } }
static void Main(string[] args) { VoxReader reader = new VoxReader(); VoxWriter writer = new VoxWriter(); if (args.Length < 2) { Console.WriteLine("[ERROR] Missing arguments"); Console.WriteLine("Usage: VoxSlicer.exe SIZE FILE"); return; } try { short size = Convert.ToInt16(args[0]); if (size >= 126) { Console.WriteLine("[ERROR] Size must be lower than 126"); return; } VoxModel model = reader.LoadModel(args[1]); if (model == null) { return; } DirectoryInfo directory = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[1])); foreach (var data in model.voxelFrames) { SchematicConstants.WidthSchematic = size; SchematicConstants.HeightSchematic = size; SchematicConstants.LengthSchematic = size; int sizeX = (int)Math.Ceiling((decimal)data.VoxelsWide / size); int sizeY = (int)Math.Ceiling((decimal)data.VoxelsTall / size); int sizeZ = (int)Math.Ceiling((decimal)data.VoxelsDeep / size); Schematic[,,] schematics = new Schematic[sizeX, sizeY, sizeZ]; Color[] colors = model.palette; for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int posX = x / size; int posY = y / size; int posZ = z / size; if (schematics[posX, posY, posZ] == null) { schematics[posX, posY, posZ] = new Schematic() { Blocks = new System.Collections.Generic.HashSet <Block>(), Heigth = size, Length = size, Width = size }; } int indexColor = data.Get(x, y, z); Color color = colors[indexColor]; if (!color.IsEmpty) { schematics[posX, posY, posZ].Blocks.Add(new Block((ushort)x, (ushort)y, (ushort)z, color.ColorToUInt())); } } } } for (int x = 0; x < schematics.GetLength(0); x++) { for (int y = 0; y < schematics.GetLength(1); y++) { for (int z = 0; z < schematics.GetLength(2); z++) { if (schematics[x, y, z].TotalCount != 0) { string name = $"{Path.GetFileNameWithoutExtension(args[1])}-{x}-{y}-{z}.vox"; Console.WriteLine("[INFO] Started to process: " + name); writer.WriteModel(Path.Combine(directory.FullName, name), schematics[x, y, z], 0, size); } } } } } } catch (Exception) { Console.WriteLine("[ERROR] Failed to read voxel volume size"); } }
public static void ProcessClientPacket(int packetID) { switch ((PacketID)packetID) { case PacketID.entityUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(creader); if (players.ContainsKey(entityUpdate.guid)) { entityUpdate.Filter(players[entityUpdate.guid]); entityUpdate.Merge(players[entityUpdate.guid]); } else { players.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.name != null) { RefreshPlayerlist(); } SendUDP(entityUpdate.Data); break; #endregion case PacketID.entityAction: #region entity action EntityAction entityAction = new EntityAction(creader); switch (entityAction.type) { case ActionType.talk: break; case ActionType.staticInteraction: break; case ActionType.pickup: break; case ActionType.drop: //send item back to dropper because dropping is disabled to prevent chatspam if (form.radioButtonDestroy.Checked) { new ChatMessage() { message = "item destroyed" }.Write(cwriter); } else { var serverUpdate = new ServerUpdate(); var pickup = new ServerUpdate.Pickup() { guid = guid, item = entityAction.item }; serverUpdate.pickups.Add(pickup); if (form.radioButtonDuplicate.Checked) { serverUpdate.pickups.Add(pickup); } serverUpdate.Write(cwriter); } break; case ActionType.callPet: var petCall = new SpecialMove() { Guid = guid }; SendUDP(petCall.data); break; default: //unknown type break; } break; #endregion case PacketID.hit: #region hit var hit = new Hit(creader); var attack = new Attack() { Target = (ushort)hit.target, Damage = hit.damage, Stuntime = hit.stuntime, Skill = hit.isYellow, Type = hit.type, ShowLight = hit.showlight == 1, Critical = hit.critical == 1 }; SendUDP(attack.data); lastTarget = attack.Target; break; #endregion case PacketID.passiveProc: #region passiveProc var passiveProc = new PassiveProc(creader); var proc = new Proc() { Target = (ushort)passiveProc.target, Type = passiveProc.type, Modifier = passiveProc.modifier, Duration = passiveProc.duration }; SendUDP(proc.data); break; #endregion case PacketID.shoot: #region shoot var shootPacket = new Resources.Packet.Shoot(creader); var shootDatagram = new Resources.Datagram.Shoot() { Position = shootPacket.position, Velocity = shootPacket.velocity, Scale = shootPacket.scale, Particles = shootPacket.particles, Projectile = shootPacket.projectile }; SendUDP(shootDatagram.data); break; #endregion case PacketID.chat: #region chat var chatMessage = new ChatMessage(creader); if (chatMessage.message.ToLower() == @"/plane") { Console.Beep(); var serverUpdate = new ServerUpdate() { blockDeltas = VoxModel.Parse("model.vox"), }; foreach (var block in serverUpdate.blockDeltas) { block.position.x += 8286946; block.position.y += 8344456; block.position.z += 220; } serverUpdate.Write(cwriter); } else { var chat = new Chat(chatMessage.message) { Sender = guid //client doesn't send this //(ushort)chatMessage.sender }; SendUDP(chat.data); } break; #endregion case PacketID.chunk: #region chunk var chunk = new Chunk(creader); break; #endregion case PacketID.sector: #region sector var sector = new Sector(creader); break; #endregion case PacketID.version: #region version var version = new ProtocolVersion(creader); if (version.version != 3) { version.version = 3; version.Write(cwriter, true); } else { var connect = new Connect(); SendUDP(connect.data); } break; #endregion default: form.Log("unknown client packet\n", Color.Magenta); break; } }