public static System.Drawing.Bitmap ToBitmap(this UniversalEditor.ObjectModels.Multimedia3D.Model.ModelObjectModel model, int width, int height, UniversalEditor.ObjectModels.Multimedia3D.Pose.PoseObjectModel pose) { System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); graphics.Clear(System.Drawing.Color.Black); IntPtr hdc = graphics.GetHdc(); Canvas canvas = new Canvas(hdc, bitmap.PixelFormat); canvas.MakeCurrent(); canvas.Matrix.Mode = MatrixMode.Projection; canvas.Matrix.Reset(); Internal.GLU.Methods.gluPerspective(45.0, 640 / 480, 0.0, 45.0); canvas.EnableDepthTesting = true; canvas.EnableNormalization = true; canvas.EnableTexturing = true; Internal.OpenGL.Methods.glTexEnv(Internal.OpenGL.Constants.TextureEnvironmentTarget.TextureEnvironment, Internal.OpenGL.Constants.TextureEnvironmentParameterName.TextureEnvironmentMode, Internal.OpenGL.Constants.TextureEnvironmentParameterValue.Modulate); canvas.CullingMode = CullingMode.Front; canvas.EnableBlending = true; Internal.OpenGL.Methods.glBlendFunc(Internal.OpenGL.Constants.GLBlendFunc.SourceAlpha, Internal.OpenGL.Constants.GLBlendFunc.OneMinusSourceAlpha); Internal.OpenGL.Methods.glEnable(Internal.OpenGL.Constants.GLCapabilities.AlphaTesting); Internal.OpenGL.Methods.glAlphaFunc(Internal.OpenGL.Constants.GLAlphaFunc.GreaterOrEqual, 0.05f); World.Lights[0].Position = new PositionVector4(0.45f, 1.45f, -4.0f, 0.0f); World.Lights[0].DiffuseColor = Color.FromRGBA(0.9f, 0.9f, 0.9f, 1.0f); World.Lights[0].AmbientColor = Color.FromRGBA(0.7f, 0.7f, 0.7f, 1.0f); World.Lights[0].SpecularColor = Color.FromRGBA(0.7f, 0.7f, 0.7f, 1.0f); World.Lights[0].Enabled = true; canvas.Matrix.Mode = MatrixMode.Projection; canvas.Reset(); canvas.Translate(0.0, -1, 0.5); canvas.Scale(0.05, 0.08, 0.1); canvas.Matrix.Mode = MatrixMode.ModelView; canvas.DrawModel(model); graphics.ReleaseHdc(); graphics.Flush(); bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX); if (pose != null) { } return bitmap; }
private void WriteVariantOpcode(UniversalEditor.IO.BinaryWriter bw, byte startOpcode, params object[] objs) { if (objs.Length == 0) throw new InvalidOperationException(); if (objs[0] is byte) { bw.Write((byte)(startOpcode + 1)); // PUSHB foreach (object obj in objs) { bw.Write((byte)obj); } } else if (objs[0] is short) { bw.Write((byte)(startOpcode + 2)); // PUSHS foreach (object obj in objs) { bw.Write((short)obj); } } else if (objs[0] is int) { bw.Write((byte)(startOpcode + 4)); // PUSHI foreach (object obj in objs) { bw.Write((int)obj); } } else if (objs[0] is long) { bw.Write((byte)(startOpcode + 8)); // PUSHL foreach (object obj in objs) { bw.Write((long)obj); } } else if (objs[0] is sbyte) { bw.Write((byte)(startOpcode + 11)); // PUSHSB foreach (object obj in objs) { bw.Write((sbyte)obj); } } else if (objs[0] is ushort) { bw.Write((byte)(startOpcode + 12)); // PUSHUS foreach (object obj in objs) { bw.Write((ushort)obj); } } else if (objs[0] is uint) { bw.Write((byte)(startOpcode + 14)); // PUSHUI foreach (object obj in objs) { bw.Write((uint)obj); } } else if (objs[0] is ulong) { bw.Write((byte)(startOpcode + 18)); // PUSHUL foreach (object obj in objs) { bw.Write((ulong)obj); } } else if (objs[0] is float) { bw.Write((byte)(startOpcode + 24)); // PUSHF foreach (object obj in objs) { bw.Write((float)obj); } } else if (objs[0] is double) { bw.Write((byte)(startOpcode + 28)); // PUSHD foreach (object obj in objs) { bw.Write((double)obj); } } }
/// <summary> /// Converts this <see cref="UniversalEditor.ObjectModels.Multimedia3D.Model.ModelObjectModel" /> to a <see cref="System.Drawing.Bitmap" />, rendering it in the given pose. /// </summary> /// <param name="model">The <see cref="UniversalEditor.ObjectModels.Multimedia3D.Model.ModelObjectModel" /> to convert into a <see cref="System.Drawing.Bitmap" />.</param> /// <param name="pose">The <see cref="UniversalEditor.ObjectModels.Multimedia3D.Pose.PoseObjectModel" /> in which to pose the model.</param> /// <returns>A <see cref="System.Drawing.Bitmap" /> containing an OpenGL-rendered image of the given <see cref="UniversalEditor.ObjectModels.Multimedia3D.Model.ModelObjectModel" /> in the given pose.</returns> public static System.Drawing.Bitmap ToBitmap(this UniversalEditor.ObjectModels.Multimedia3D.Model.ModelObjectModel model, UniversalEditor.ObjectModels.Multimedia3D.Pose.PoseObjectModel pose) { return ToBitmap(model, 640, 480, pose); }