Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const float OBJ_SIZE = 1.965f;
- const float PIXEL_SIZE = 0.1f;
- float scale = PIXEL_SIZE / OBJ_SIZE;
- var colors = new Dictionary<string, Color>
- {
- ["o972020"] = Color.Yellow,
- ["o972021"] = Color.Red,
- ["o972022"] = Color.Blue,
- ["o972023"] = Color.Green,
- ["o972024"] = Color.Purple,
- ["o972025"] = Color.Black,
- ["o972026"] = Color.White,
- };
- Bitmap bmp = new Bitmap(@"C:\Users\Joseph\Desktop\test.png");
- MSB64 msbh = MSB64.Read($"{ds3}\\map\\mapstudio\\m30_00_00_00.msb.dcx.bak");
- var crate = msbh.Parts.Objects.Where(obj => obj.ModelName == "o001080").First();
- var model = msbh.Models.Objects.Where(mod => mod.Name == "o001080").First();
- MSB64 msb = MSB64.Read($"{ds3}\\map\\mapstudio\\m54_00_00_00.msb.dcx.bak");
- foreach (string color in colors.Keys)
- {
- var mod = new MSB64.Model.Object(model);
- mod.Name = color;
- mod.ID = msb.Models.Objects.Count;
- msb.Models.Objects.Add(mod);
- }
- string[,] objs = new string[bmp.Width, bmp.Height];
- for (int x = 0; x < bmp.Width; x++)
- {
- for (int y = 0; y < bmp.Height; y++)
- {
- Color c = bmp.GetPixel(x, y);
- if (c.A > 32)
- {
- string bestObj = null;
- float bestDist = 1000;
- foreach (string color in colors.Keys)
- {
- Vector3 dist = new Vector3(c.R, c.G, c.B) - new Vector3(colors[color].R, colors[color].G, colors[color].B);
- if (dist.Length() < bestDist)
- {
- bestObj = color;
- bestDist = dist.Length();
- }
- }
- objs[x, y] = bestObj;
- }
- else
- {
- objs[x, y] = null;
- }
- }
- }
- for (int y = 0; y < bmp.Height; y++)
- {
- for (int x = 0; x < bmp.Width; x++)
- {
- if (objs[x, y] == null)
- continue;
- int width = 1;
- for (int w = 1; w < bmp.Width - x; w++)
- {
- if (objs[x + w, y] != objs[x, y])
- break;
- else
- width++;
- }
- var obj = new MSB64.Part.Object(crate);
- obj.DrawGroup1 = 0xFFFFFFFF;
- obj.DrawGroup2 = 0xFFFFFFFF;
- obj.DrawGroup3 = 0xFFFFFFFF;
- obj.DrawGroup4 = 0xFFFFFFFF;
- obj.CollisionName = "h000100";
- obj.ID = msb.Parts.Objects.Count;
- obj.Name = objs[x, y] + "_" + obj.ID;
- obj.ModelName = objs[x, y];
- obj.Position = new Vector3(0 + bmp.Width / 2f * PIXEL_SIZE - x * PIXEL_SIZE - (width * PIXEL_SIZE / 2f), bmp.Height * PIXEL_SIZE + 0 - y * PIXEL_SIZE, 0);
- obj.Rotation = new Vector3(0);
- obj.Scale = new Vector3(scale * width, scale, scale);
- msb.Parts.Objects.Add(obj);
- x += width - 1;
- }
- }
- msb.Write($"{ds3}\\map\\mapstudio\\m54_00_00_00.msb.dcx");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement