Ejemplo n.º 1
0
        //get new pos and correct ingame bounds for child
        public static dynamic getposandbounds(dynamic whatever)
        {
            dynamic child = whatever.DeepClone();
            string  uuid  = child.shapeId;

            //if (child.bounds == null) //add bounds to parts (blocks do not get affected)
            {
                if (Database.blocks.ContainsKey(uuid))
                {
                    Blockobject b = Database.blocks[uuid];
                    if (b is Part)
                    {
                        child.bounds = ((Part)b).GetBoundsDynamic();
                    }
                }
                else
                {
                    missingmod = true;
                }

                if (child.bounds == null)
                {
                    child.bounds = new JObject {
                        ["x"] = 1, ["y"] = 1, ["z"] = 1
                    };
                }
            }
            bool IsJoint = false;

            if (child.posA != null)
            {
                IsJoint     = true;
                child.pos   = child.posA;
                child.xaxis = child.xaxisA;
                child.zaxis = child.zaxisA;
            }

            try
            {
                int xaxis    = Convert.ToInt32(child.xaxis);
                int zaxis    = Convert.ToInt32(child.zaxis);
                int xaxisabs = Math.Abs(xaxis);
                int zaxisabs = Math.Abs(zaxis);

                if (xaxisabs == 3)
                {
                    if (zaxisabs == 2)
                    {
                        child.bounds = new JObject {
                            ["x"] = child.bounds.y, ["y"] = child.bounds.z, ["z"] = child.bounds.x
                        };
                    }
                    else
                    if (zaxisabs == 1)
                    {
                        child.bounds = new JObject {
                            ["x"] = child.bounds.z, ["y"] = child.bounds.y, ["z"] = child.bounds.x
                        };
                    }
                    else
                    {
                        brokenrotation = true;
                    }
                }
                else if (xaxisabs == 2)
                {
                    if (zaxisabs == 3)
                    {
                        child.bounds = new JObject {
                            ["x"] = child.bounds.y, ["y"] = child.bounds.x, ["z"] = child.bounds.z
                        };
                    }
                    else
                    if (zaxisabs == 1)
                    {
                        child.bounds = new JObject {
                            ["x"] = child.bounds.z, ["y"] = child.bounds.x, ["z"] = child.bounds.y
                        };
                    }
                    else
                    {
                        brokenrotation = true;
                    }
                }
                else if (xaxisabs == 1)
                {
                    if (zaxisabs == 2)
                    {
                        child.bounds = new JObject {
                            ["x"] = child.bounds.x, ["y"] = child.bounds.z, ["z"] = child.bounds.y
                        };
                    }
                    else if (zaxisabs != 3)
                    {
                        brokenrotation = true;
                    }
                }
                else
                {
                    brokenrotation = true;
                }

                //this updating pos only applies to parts, blocks do not get affected as they always have xaxis 1 zaxis 3
                if (!IsJoint)
                {
                    if (xaxis == -1 | zaxis == -1 | (xaxis == 2 && zaxis == 3) | (xaxis == 3 && zaxis == -2) | (xaxis == -2 && zaxis == -3) | (xaxis == -3 && zaxis == 2))
                    {
                        child.pos.x -= child.bounds.x;
                    }
                    if (xaxis == -2 | zaxis == -2 | (xaxis == -1 && zaxis == 3) | (xaxis == -3 && zaxis == -1) | (xaxis == 1 && zaxis == -3) | (xaxis == 3 && zaxis == 1))
                    {
                        child.pos.y -= child.bounds.y;
                    }
                    if (xaxis == -3 | zaxis == -3 | (xaxis == -2 && zaxis == 1) | (xaxis == -1 && zaxis == -2) | (xaxis == 1 && zaxis == 2) | (xaxis == 2 && zaxis == -1))
                    {
                        child.pos.z -= child.bounds.z;
                    }
                }
                else
                {
                    if (!(zaxis > 0 || !(child.bounds.x != 1 || child.bounds.y != 1 || child.bounds.z != 1)))
                    {
                        //correctedchild.pos = Blueprint.joints[i].posB;
                        if (zaxis == -1)
                        {
                            child.pos.x -= child.bounds.x - 1;
                        }
                        if (zaxis == -2)
                        {
                            child.pos.y -= child.bounds.y - 1;
                        }
                        if (zaxis == -3)
                        {
                            child.pos.z -= child.bounds.z - 1;
                        }
                    }
                }
            }
            catch
            {
            }
            return(child);
        }
Ejemplo n.º 2
0
        public static Tuple <Model3DGroup, Model3DGroup> RenderBlocks()
        {
            Model3DGroup blocks = new Model3DGroup();
            Model3DGroup glass  = new Model3DGroup();

            Block block = new Block(null, "unknown", "unknown", null, null);

            if (Blueprint.bodies != null)
            {
                foreach (dynamic body in Blueprint.bodies)
                {
                    foreach (dynamic child in body.childs)
                    {
                        dynamic realpos = getposandbounds(child);
                        int     x       = realpos.pos.x;
                        int     y       = realpos.pos.y;
                        int     z       = realpos.pos.z;

                        if (Database.blocks.ContainsKey(child.shapeId.ToString()))
                        {
                            Blockobject blockobject = Database.blocks[child.shapeId.ToString()];
                            if (blockobject is Block)
                            {
                                Model3D model = (blockobject as Block).Render(x, y, z, realpos.bounds, child.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));
                                if (!blockobject.glass)
                                {
                                    blocks.Children.Add(model);
                                }
                                else
                                {
                                    glass.Children.Add(model);
                                }
                            }
                            else//part
                            {
                                Model3D model = (blockobject as Part).Render(x, y, z, child.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));
                                if (!blockobject.glass)
                                {
                                    blocks.Children.Add(model);
                                }
                                else
                                {
                                    glass.Children.Add(model);
                                }
                            }
                        }
                        else//not in database
                        {
                            dynamic bounds = new JObject()
                            {
                                ["x"] = 1, ["y"] = 1, ["z"] = 1
                            };
                            if (realpos.bounds != null)
                            {
                                bounds = realpos.bounds;
                            }

                            Model3D model = block.Render(x, y, z, bounds, child.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));

                            blocks.Children.Add(model);
                        }
                    }
                }
            }
            if (Blueprint.joints != null)
            {
                foreach (dynamic joint in Blueprint.joints)
                {
                    dynamic realpos = getposandbounds(joint);
                    int     x       = realpos.pos.x;
                    int     y       = realpos.pos.y;
                    int     z       = realpos.pos.z;

                    if (Database.blocks.ContainsKey(joint.shapeId.ToString()))
                    {
                        Blockobject blockobject = Database.blocks[joint.shapeId.ToString()];
                        if (blockobject is Block)
                        {
                            Model3D model = (blockobject as Block).Render(x, y, z, realpos.bounds, joint.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));
                            if (!blockobject.glass)
                            {
                                blocks.Children.Add(model);
                            }
                            else
                            {
                                glass.Children.Add(model);
                            }
                        }
                        else//part
                        {
                            Model3D model = (blockobject as Part).Render(x, y, z, joint.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));
                            if (!blockobject.glass)
                            {
                                blocks.Children.Add(model);
                            }
                            else
                            {
                                glass.Children.Add(model);
                            }
                        }
                    }
                    else//not in database
                    {
                        dynamic bounds = new JObject()
                        {
                            ["x"] = 1, ["y"] = 1, ["z"] = 1
                        };
                        if (realpos.bounds != null)
                        {
                            bounds = realpos.bounds;
                        }

                        Model3D model = block.Render(x, y, z, bounds, joint.color.ToString(), Convert.ToInt32(realpos.xaxis), Convert.ToInt32(realpos.zaxis));

                        blocks.Children.Add(model);
                    }
                }
            }
            new Task(() =>
            {
                if (BP.missingmod)
                {
                    MessageBox.Show("Missing mod for this blueprint! \nPlease download the required mod!\n\nwill work for now tho wiring/moving blocks not recommended!");
                }
            }).Start();
            new Task(() =>
            {
                if (BP.brokenrotation)
                {
                    MessageBox.Show("Broken Rotation in this blueprint!\n\nTools 'mirror tool', [] ,.. will BREAK your blueprint!");
                }
            }).Start();
            return(new Tuple <Model3DGroup, Model3DGroup>(blocks, glass));
        }