Exemple #1
0
        private static void RenderModelGetScreenMinMax(Model3DNode model, M3D.Model.Utils.Vector3 rotation, M3D.Model.Utils.Vector3 translation, M3D.Model.Utils.Vector3 scale, out Rectangle screen_rec)
        {
            var     scale1       = Matrix4.CreateScale(scale.X, scale.Y, scale.Z);
            Matrix4 matrix4_1    = Matrix4.CreateRotationY(rotation.Y * ((float)Math.PI / 180f)) * Matrix4.CreateRotationX(rotation.X * ((float)Math.PI / 180f)) * Matrix4.CreateRotationZ(rotation.Z * ((float)Math.PI / 180f));
            var     translation1 = Matrix4.CreateTranslation(translation.X, translation.Y, translation.Z);
            Matrix4 matrix4_2    = matrix4_1;
            Matrix4 mat          = scale1 * matrix4_2 * translation1;

            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.Rotate(-90f, new OpenTK.Vector3(1f, 0.0f, 0.0f));
            GL.MultMatrix(ref mat);
            Color4 diffuse    = model.Diffuse;
            var    brightness = model.Brightness;
            var    highlight  = model.Highlight;

            if (ImageCapture.IconColor == "Standard")
            {
                model.Diffuse = new Color4(98, 181, 233, byte.MaxValue);
            }
            else if (ImageCapture.IconColor == "Random")
            {
                FilamentConstants.HexToRGB(FilamentConstants.generateHEXFromColor((FilamentConstants.ColorsEnum)(ImageCapture.internalRandomGenerator.Next(10) + 5)), out var R, out var G, out var B, out var A);
                model.Diffuse = new Color4(R, G, B, A);
            }
            model.Brightness = 1f;
            model.Highlight  = false;
            model.Render3D();
            model.Diffuse    = diffuse;
            model.Brightness = brightness;
            model.Highlight  = highlight;
            screen_rec       = ImageCapture.GetScreenMinMax(model);
            GL.PopMatrix();
        }
Exemple #2
0
 void PopulateChildren(ModelNode node, Model3DNode orin, Model model, AnimationEngine engine, List <ModelNode> allNodes)
 {
     allNodes.Add(node);
     if (engine.HeadBones.Contains(node.Name))
     {
         node.Mode = 0;
     }
     else if (engine.LegBones.Contains(node.Name))
     {
         node.Mode = 2;
     }
     else
     {
         node.Mode = 1;
     }
     for (int i = 0; i < orin.Children.Count; i++)
     {
         ModelNode child = new ModelNode()
         {
             Parent = node, Name = orin.Children[i].Name.ToLowerFast()
         };
         PopulateChildren(child, orin.Children[i], model, engine, allNodes);
         node.Children.Add(child);
     }
 }
Exemple #3
0
        private static Bitmap GenerateIcon(Model3DNode model, GLControl glcontrol, Vector2 icon_size, M3D.Model.Utils.Vector3 orientation, Color4 bgColor)
        {
            ImageCapture.SetViewPoint(glcontrol);
            var rotation    = new M3D.Model.Utils.Vector3(orientation);
            var translation = new M3D.Model.Utils.Vector3(0.0f, 0.0f, 0.0f);

            M3D.Model.Utils.Vector3 ext = model.CalculateMinMax().Ext;
            var num   = ext.X <= (double)ext.Z ? ext.Z <= (double)ext.Y ? 100f / ext.Y : 100f / ext.Z : ext.Y <= (double)ext.X ? 100f / ext.X : 100f / ext.Y;
            var scale = new M3D.Model.Utils.Vector3(num, num, num);

            ImageCapture.SetupForIconRender(new OpenTK.Vector3(100f, 100f, 250f), new OpenTK.Vector3(0.0f, 0.0f, 0.0f), bgColor);
            ImageCapture.RenderModelGetScreenMinMax(model, rotation, translation, scale, out Rectangle screen_rec);
            return(ImageCapture.GrabIconFromRender(glcontrol, ref screen_rec, icon_size));
        }
Exemple #4
0
        List <Model3DNode> GetNodes(Model3DNode node)
        {
            List <Model3DNode> nodes = new List <Model3DNode>();

            nodes.Add(node);
            if (node.Children.Count > 0)
            {
                for (int i = 0; i < node.Children.Count; i++)
                {
                    nodes.AddRange(GetNodes(node.Children[i]));
                }
            }
            return(nodes);
        }
Exemple #5
0
 public Micro1CaseNode()
 {
     PrinterModel = new Model3DNode(3000);
     PrinterModel.SetModel(LoadModel(Path.Combine(Paths.GUIObjectsFolder, "printer.m3d")));
     PrinterColor           = new Color4(0.1686275f, 0.7529412f, 0.9529412f, 1f);
     PrinterModel.Shininess = 30f;
     PrinterModel.Ambient   = new Color4(PrinterColor.R / 4f, PrinterColor.G / 4f, PrinterColor.B / 4f, 1f);
     PrinterModel.Diffuse   = PrinterColor;
     PrinterModel.Specular  = new Color4(0.4f, 0.4f, 0.4f, 1f);
     PrinterBed             = new Model3DNode(3001);
     PrinterBed.SetModel(LoadModel(Path.Combine(Paths.GUIObjectsFolder, "bed.m3d")));
     PrinterBed.Shininess = 30f;
     PrinterBed.TranslateModelData(0.0f, 0.0f, -47.6f);
     PrinterBed.Ambient  = new Color4(PrinterColor.R / 4f, PrinterColor.G / 4f, PrinterColor.B / 4f, 1f);
     PrinterBed.Diffuse  = PrinterColor;
     PrinterBed.Specular = new Color4(0.4f, 0.4f, 0.4f, 1f);
     PrinterLogo         = new PrinterLogoObjectNode(Path.Combine(Paths.GUIImagesFolder, "m3d.png"), 3002, new Vector3(0.0f, -75f, -60f), new Vector3(40f, 0.0f, 11f));
     AddChildElement(PrinterLogo);
     AddChildElement(PrinterModel);
     AddChildElement(PrinterBed);
 }
Exemple #6
0
        private static Rectangle GetScreenMinMax(Model3DNode model)
        {
            int[]    numArray = new int[4];
            double[] data1    = new double[16];
            double[] data2    = new double[16];
            GL.GetInteger(GetPName.Viewport, numArray);
            GL.GetDouble(GetPName.Modelview0MatrixExt, data1);
            GL.GetDouble(GetPName.ProjectionMatrix, data2);
            var       right      = new Matrix4((float)data2[0], (float)data2[1], (float)data2[2], (float)data2[3], (float)data2[4], (float)data2[5], (float)data2[6], (float)data2[7], (float)data2[8], (float)data2[9], (float)data2[10], (float)data2[11], (float)data2[12], (float)data2[13], (float)data2[14], (float)data2[15]);
            var       left       = new Matrix4((float)data1[0], (float)data1[1], (float)data1[2], (float)data1[3], (float)data1[4], (float)data1[5], (float)data1[6], (float)data1[7], (float)data1[8], (float)data1[9], (float)data1[10], (float)data1[11], (float)data1[12], (float)data1[13], (float)data1[14], (float)data1[15]);
            var       screen_max = new M3D.Model.Utils.Vector3(float.MinValue, float.MinValue, float.MinValue);
            var       screen_min = new M3D.Model.Utils.Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            ModelSize minMax     = model.CalculateMinMax();

            M3D.Model.Utils.Vector3 min = minMax.Min;
            M3D.Model.Utils.Vector3 max = minMax.Max;
            M3D.Model.Utils.Vector3 ext = minMax.Ext;
            var coord1 = new M3D.Model.Utils.Vector3(min);

            ImageCapture.UpdateScreenMinMax(coord1, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord1.X = max.X;
            ImageCapture.UpdateScreenMinMax(coord1, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord1.Z = max.Z;
            ImageCapture.UpdateScreenMinMax(coord1, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord1.X = min.X;
            ImageCapture.UpdateScreenMinMax(coord1, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            var coord2 = new M3D.Model.Utils.Vector3(max);

            ImageCapture.UpdateScreenMinMax(coord2, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord2.X = min.X;
            ImageCapture.UpdateScreenMinMax(coord2, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord2.Z = min.Z;
            ImageCapture.UpdateScreenMinMax(coord2, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            coord2.X = max.X;
            ImageCapture.UpdateScreenMinMax(coord2, ref screen_min, ref screen_max, Matrix4.Mult(left, right), numArray);
            return(new Rectangle((int)screen_min.X, (int)screen_min.Y, (int)(screen_max.X - (double)screen_min.X), (int)(screen_max.Y - (double)screen_min.Y)));
        }
Exemple #7
0
 public void HandleWheels()
 {
     if (!hasWheels)
     {
         Model mod = TheServer.Models.GetModel(model);
         if (mod == null) // TODO: mod should return a cube when all else fails?
         {
             return;
         }
         Model3D scene = mod.Original;
         if (scene == null) // TODO: Scene should return a cube when all else fails?
         {
             return;
         }
         SetOrientation(Quaternion.Identity);
         List <Model3DNode>       nodes       = GetNodes(scene.RootNode);
         List <VehiclePartEntity> frontwheels = new List <VehiclePartEntity>();
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix      mat   = nodes[i].MatrixA;
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     mat   = tnode.MatrixA * mat;
                     tnode = tnode.Parent;
                 }
                 Location          pos   = GetPosition() + new Location(mat.M14, mat.M34, mat.M24) + offset; // NOTE: wtf happened to this matrix?
                 VehiclePartEntity wheel = new VehiclePartEntity(TheRegion, "vehicles/" + vehName + "_wheel", true);
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(Quaternion.Identity);
                 wheel.Gravity = Gravity;
                 wheel.CGroup  = CGroup;
                 wheel.SetMass(30);
                 wheel.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(wheel);
                 wheel.SetPosition(pos);
                 if (name.After("wheel").StartsWith("f"))
                 {
                     SteeringMotors.Add(ConnectWheel(wheel, false, true));
                     frontwheels.Add(wheel);
                 }
                 else if (name.After("wheel").StartsWith("b"))
                 {
                     DrivingMotors.Add(ConnectWheel(wheel, true, true));
                 }
                 else
                 {
                     ConnectWheel(wheel, true, false);
                 }
                 wheel.Body.ActivityInformation.Activate();
             }
         }
         if (frontwheels.Count == 2)
         {
             JointSpinner js = new JointSpinner(frontwheels[0], frontwheels[1], new Location(1, 0, 0));
             TheRegion.AddJoint(js);
         }
         hasWheels = true;
     }
 }
Exemple #8
0
 public void HandleWheels()
 {
     if (!hasWheels)
     {
         string wheelsModFront  = SourceFile.GetString("vehicle.wheels.front.model");
         string wheelsModBack   = SourceFile.GetString("vehicle.wheels.back.model");
         double wheelsSuspFront = SourceFile.GetDouble("vehicle.wheels.front.suspension", 0.1).Value;
         double wheelsSuspBack  = SourceFile.GetDouble("vehicle.wheels.back.suspension", 0.1).Value;
         Model  mod             = TheServer.Models.GetModel(model);
         if (mod == null) // TODO: mod should return a cube when all else fails?
         {
             return;
         }
         Model3D scene = mod.Original;
         if (scene == null) // TODO: Scene should return a cube when all else fails?
         {
             return;
         }
         SetOrientation(BEPUutilities.Quaternion.Identity); // TODO: Track and reset orientation maybe?
         List <Model3DNode>       nodes       = GetNodes(scene.RootNode);
         List <VehiclePartEntity> frontwheels = new List <VehiclePartEntity>();
         Location centerOfMass = Location.Zero;
         double   mass         = 0;
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 centerOfMass += (new Location(mat.M41, -mat.M43, mat.M42) + offset) * 30; // TODO: Arbitrary constant
                 mass         += 30;                                                       // TODO: Arbitrary constant
             }
             else if (name.Contains("flap"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 centerOfMass += (new Location(mat.M41, -mat.M43, mat.M42) + offset) * 20; // TODO: Arbitrary constant
                 mass         += 20;                                                       // TODO: Arbitrary constant
             }
         }
         if (mass > 0)
         {
             centerOfMass /= mass;
         }
         Body.CollisionInformation.LocalPosition = -centerOfMass.ToBVector() - CenterOfMassOffset.ToBVector();
         ForceNetwork();
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 Location          pos   = GetPosition() + new Location(Body.CollisionInformation.LocalPosition) + new Location(mat.M41, -mat.M43, mat.M42) + offset; // TODO: matrix gone funky?
                 VehiclePartEntity wheel = new VehiclePartEntity(TheRegion, (name.After("wheel").Contains("f") ? wheelsModFront : wheelsModBack), true);
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(BEPUutilities.Quaternion.Identity);
                 wheel.Gravity = Gravity;
                 wheel.CGroup  = CGroup;
                 wheel.SetMass(30); // TODO: Arbitrary constant
                 wheel.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(wheel);
                 wheel.ForceNetwork();
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(BEPUutilities.Quaternion.Identity);
                 if (name.After("wheel").Contains("f"))
                 {
                     SteeringMotors.Add(ConnectWheel(wheel, false, true, wheelsSuspFront));
                     frontwheels.Add(wheel);
                 }
                 else if (name.After("wheel").Contains("b"))
                 {
                     DrivingMotors.Add(ConnectWheel(wheel, true, true, wheelsSuspBack));
                 }
                 else
                 {
                     ConnectWheel(wheel, true, false, wheelsSuspBack);
                 }
                 wheel.Body.ActivityInformation.Activate();
             }
             else if (name.Contains("flap"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 Location          pos     = GetPosition() + new Location(Body.CollisionInformation.LocalPosition) + new Location(mat.M41, -mat.M43, mat.M42) + offset; // TODO: matrix gone funky?
                 FDSSection        flapDat = SourceFile.GetSection("vehicle.flaps").GetSection(name.After("flap").Replace("_", ""));
                 VehiclePartEntity flap    = new VehiclePartEntity(TheRegion, flapDat.GetString("model"), true);
                 flap.SetPosition(pos);
                 flap.SetOrientation(BEPUutilities.Quaternion.Identity);
                 flap.Gravity = Gravity;
                 flap.CGroup  = CGroup;
                 flap.SetMass(20);
                 flap.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(flap);
                 flap.ForceNetwork();
                 flap.SetPosition(pos);
                 flap.SetOrientation(BEPUutilities.Quaternion.Identity);
                 ConnectFlap(flap, flapDat);
             }
         }
         if (frontwheels.Count == 2)
         {
             JointSpinner js = new JointSpinner(frontwheels[0], frontwheels[1], new Location(1, 0, 0));
             TheRegion.AddJoint(js);
         }
         hasWheels = true;
     }
 }