public DMesh(string n) { name = n; vertex = new List <Vector3>(); triangle = new List <DTriangle>(); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id = new List <int>(); #endif tex_name = new List <string>(); light = new List <DLight>(); #if OVERLOAD_LEVEL_EDITOR color = new List <Color>(); #else color = new List <Vector3>(); #endif for (int i = 0; i < NUM_LIGHTS; i++) { DLight dl = new DLight(Vector3.Zero); light.Add(dl); } for (int i = 0; i < NUM_COLORS; i++) { #if OVERLOAD_LEVEL_EDITOR color.Add(Color.White); #else color.Add(Vector3.One); #endif } }
public void CopyLights() { for (int i = 0; i < DMesh.NUM_LIGHTS; i++) { copy_lights[i] = new DLight(m_active_dmesh.light[i]); } copied_lights = true; }
private void label_light_flare_MouseDown(object sender, MouseEventArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.CycleFlare(); UpdateLightProperties(dl); } }
private void label_light_color_MouseDown(object sender, MouseEventArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.CycleColorIndex(); UpdateLightProperties(dl); } }
public float ROT_SNAP = Utility.RAD_180 / 36f; // 5 degrees private void slider_light_rot_yaw_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.rot_yaw = Utility.SnapValue(dl.rot_yaw + e.Increment * ROT_SNAP, ROT_SNAP); UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void button_light_reset_pos_Click(object sender, EventArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.position = Vector3.Zero; UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void checklist_lights_SelectedIndexChanged(object sender, EventArgs e) { m_selected_light = Utility.Clamp(checklist_lights.SelectedIndex, 0, 3); if (m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void slider_light_range_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.range = Utility.SnapValue(dl.range + e.Increment * 0.5f, 0.5f); dl.range = Utility.Clamp(dl.range, 0f, 50f); UpdateLightProperties(dl); } }
private void label_light_type_MouseDown(object sender, MouseEventArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.CycleStyle(); UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void slider_light_angle_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.angle = Utility.SnapValue(dl.angle + e.Increment * 5, 5f); dl.angle = Utility.Clamp(dl.angle, 0f, 160f); UpdateLightProperties(dl); } }
private void button_light_reset_pos_Click(object sender, EventArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.position = Vector3.Zero; UpdateLightProperties(dl); RefreshGeometry(); } }
private void checklist_lights_SelectedIndexChanged(object sender, EventArgs e) { m_selected_light = Utility.Clamp(checklist_lights.SelectedIndex, 0, 3); if (m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; UpdateLightProperties(dl); RefreshGeometry(false); } }
// NOTE: Z and Y are flipped on purpose (because of how decals are oriented vs. displayed) private void slider_light_posz_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.position.Y = Utility.SnapValue(dl.position.Y + e.Increment * POS_SNAP, POS_SNAP); UpdateLightProperties(dl); RefreshGeometry(); } }
public void MoveSelectedLight(Vector3 dir, bool fast) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.position += dir * (fast ? 0.25f : 0.03125f); UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void slider_light_rot_pitch_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.rot_pitch = Utility.SnapValue(dl.rot_pitch + e.Increment * ROT_SNAP, ROT_SNAP); UpdateLightProperties(dl); RefreshGeometry(); } }
private void label_light_type_MouseDown(object sender, MouseEventArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.CycleStyle(); UpdateLightProperties(dl); RefreshGeometry(); } }
private void button_light_reset_rot_Click(object sender, EventArgs e) { if (m_selected_light >= 0 && m_active_dmesh != null) { DLight dl = m_active_dmesh.light[m_selected_light]; dl.rot_yaw = 0f; dl.rot_pitch = 0f; UpdateLightProperties(dl); gl_custom.Invalidate(); } }
private void button_light_reset_rot_Click(object sender, EventArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; dl.rot_yaw = 0f; dl.rot_pitch = 0f; UpdateLightProperties(dl); RefreshGeometry(); } }
private void slider_light_intensity_Feedback(object sender, SliderLabelArgs e) { if (m_selected_light >= 0 && m_dmesh != null) { DLight dl = m_dmesh.light[m_selected_light]; float inc = (dl.intensity < 2f ? 0.1f : 0.5f); dl.intensity = Utility.SnapValue(dl.intensity + e.Increment * inc, inc); dl.intensity = Utility.Clamp(dl.intensity, 0f, 50f); UpdateLightProperties(dl); } }
public void Copy(DLight src) { enabled = src.enabled; position = src.position; style = src.style; flare = src.flare; _rot_yaw = src._rot_yaw; _rot_pitch = src._rot_pitch; color_index = src.color_index; intensity = src.intensity; range = src.range; angle = src.angle; _rotation = src._rotation; }
// Get the rotation matrix for the spot light, in decal modeling space public static Matrix4 CalculateRotationMatrix(DLight l) { // Get the orientation for the user factors var user_set_orient = Quaternion.FromAxisAngle(Vector3.UnitX, l.rot_pitch) * Quaternion.FromAxisAngle(Vector3.UnitY, -l.rot_yaw); // Get the orientation that will make the user factors start from a spot light that points out from the decal var decal_to_spot_space = Quaternion.FromAxisAngle(Vector3.UnitX, -Utility.RAD_90); // Combine the two so that the default spot light orientation is independent of the user factor orientation // finally arriving at a Decal-To-Spotlight rotation. var new_orientation_std = (user_set_orient * Quaternion.Conjugate(decal_to_spot_space)).Normalized(); var new_orientation_dts = Quaternion.Conjugate(new_orientation_std); return(Matrix4.CreateFromQuaternion(new_orientation_dts)); }
public void UpdateLightProperties(DLight dl) { label_light_type.Text = "Style: " + dl.style.ToString(); label_light_flare.Text = "Security: " + dl.flare.ToString(); label_light_color.Text = "Color: " + (dl.color_index + 1).ToString(); slider_light_intensity.ValueText = Utility.ConvertFloatTo1Dec(dl.intensity); slider_light_range.ValueText = Utility.ConvertFloatTo1Dec(dl.range); slider_light_angle.ValueText = ((int)dl.angle).ToString(); // Z and Y are flipped on purpose due to how Decals are oriented slider_light_posx.ValueText = Utility.ConvertFloatTo1Thru3Dec(dl.position.X); slider_light_posy.ValueText = Utility.ConvertFloatTo1Thru3Dec(dl.position.Z); slider_light_posz.ValueText = Utility.ConvertFloatTo1Thru3Dec(dl.position.Y); slider_light_rot_yaw.ValueText = Utility.ConvertFloatTo1Dec(Utility.SnapValue(dl.rot_yaw / Utility.RAD_180 * 180, 1f)); slider_light_rot_pitch.ValueText = Utility.ConvertFloatTo1Dec(Utility.SnapValue(dl.rot_pitch / Utility.RAD_180 * 180, 1f)); }
public void Copy(DMesh src, bool ignore_light = false) { name = src.name; flags = src.flags; for (int i = 0; i < src.vertex.Count; i++) { vertex.Add(src.vertex[i]); } for (int i = 0; i < src.triangle.Count; i++) { DTriangle dtri = new DTriangle(src.triangle[i], 0); triangle.Add(dtri); } CopyExtraProperties(src); for (int i = 0; i < src.tex_name.Count; i++) { tex_name.Add(src.tex_name[i]); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Add(src.m_tex_gl_id[i]); #endif } if (!ignore_light) { light.Clear(); for (int i = 0; i < src.light.Count; i++) { DLight dl = new DLight(src.light[i]); light.Add(dl); } color.Clear(); for (int i = 0; i < src.color.Count; i++) { color.Add(src.color[i]); } } }
public void DrawDMesh() { GL.PushMatrix(); GL.Enable(EnableCap.PolygonOffsetFill); GL.PolygonOffset(1f, 1f); GL.Enable(EnableCap.ColorMaterial); GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.Diffuse); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); switch (m_view_type) { case ViewType.FRONT: break; case ViewType.TOP: GL.Rotate(-90, Vector3.UnitX); break; case ViewType.RIGHT: GL.Rotate(90, Vector3.UnitY); break; case ViewType.PERSP: break; } GL.Enable(EnableCap.Lighting); GL.Disable(EnableCap.Light1); switch (editor.m_lighting_type) { case LightingType.NONE: GL.Disable(EnableCap.Lighting); break; case LightingType.BRIGHT: GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); GL.Enable(EnableCap.Light1); break; case LightingType.DARK: GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); GL.Disable(EnableCap.Light1); break; } // Draw DMesh Geometry if (DrawTexture()) { SetAmbientColor(C_ambient_solid); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, editor.tm_decal.m_gl_id[0]); } else { GL.Disable(EnableCap.Texture2D); SetAmbientColor(C_ambient_objects); } // Draw base geometry texture/flat if (DrawSolid()) { SetDiffuseObjectColor(C_base); GL.CallList(GL_DECAL); } GL.PolygonOffset(0f, 0f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.ColorMaterial); GL.LineWidth(1f); // Vert normals if (editor.m_vert_display == VertDisplay.SHOW) { GL.CallList(GL_VERT_NORMALS); } // Lights for (int i = 0; i < DMesh.NUM_LIGHTS; i++) { if (editor.m_dmesh.light[i].enabled) { DLight dl = editor.m_dmesh.light[i]; if (i == editor.m_selected_light) { GL.Color3(Color.GreenYellow); } else { GL.Color3(Color.LightYellow); } GL.PushMatrix(); GL.Translate(dl.position); GL.CallList(GL_LIGHT); if (dl.style == LightStyle.SPOT) { var light_rotation = dl.rotation; GL.MultMatrix(ref light_rotation); GL.CallList(GL_LIGHT_CONE); } GL.PopMatrix(); } } // Draw base geometry wireframe if (DrawWireframe()) { if (DrawTexture()) { GL.Color3(C_text_wire); } else { GL.Color3(C_base_wire); } GL.CallList(GL_DECAL_OUTLINE); } // Draw base verts if (editor.m_edit_mode == EditMode.VERT) { GL.PointSize(4f); GL.CallList(GL_VERTS); } // Draw selected GL.Disable(EnableCap.DepthTest); GL.LineWidth(3f); GL.PointSize(8f); GL.CallList(GL_SELECT); // Draw marked GL.Disable(EnableCap.DepthTest); GL.LineWidth(1f); GL.PointSize(4f); GL.CallList(GL_MARKED); if (m_view_type == ViewType.PERSP && editor.m_gimbal_display == GimbalDisplay.SHOW) { GL.Enable(EnableCap.Blend); GL.Disable(EnableCap.DepthTest); GL.CallList(GL_GIMBAL); } if (editor.m_cut_poly_state == 1) { GL.Color4(C_grid3); GL.Enable(EnableCap.Blend); GL.Disable(EnableCap.DepthTest); GL.CallList(GL_CUT_EDGE1); } GL.PopMatrix(); }
public void Deserialize(JObject root) { vertex.Clear(); triangle.Clear(); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Clear(); #endif tex_name.Clear(); Vector3 vec = Vector3.Zero; JArray j_verts = root["verts"].GetArray(); foreach (JObject j_vert in j_verts) { vec.X = j_vert["x"].GetFloat(0.0f); vec.Y = j_vert["y"].GetFloat(0.0f); vec.Z = j_vert["z"].GetFloat(0.0f); vertex.Add(vec); } #if OVERLOAD_LEVEL_EDITOR DeserializePolys(root); #endif JObject j_tris = root["triangles"].GetObject(); foreach (var kvp in j_tris) { JObject j_tri = kvp.Value.GetObject(); DTriangle d_tri = new DTriangle(j_tri); triangle.Add(d_tri); } JArray j_tex_names = root["tex_names"].GetArray(); for (int i = 0; i < j_tex_names.Count; i++) { #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Add(-1); #endif tex_name.Add(j_tex_names[i].GetString("")); } JObject j_lights = root["lights"].GetObject(); if (j_lights.Count > 0) { light.Clear(); } int count = 0; foreach (var kvp in j_lights) { JObject j_light = kvp.Value.GetObject(); DLight d_light = new DLight(j_light); if (count < 4) { light.Add(d_light); count += 1; } } int cr, cg, cb; count = 0; JArray j_colors = root["colors"].GetArray(); if (j_colors.Count > 0) { color.Clear(); } foreach (JObject j_color in j_colors) { #if OVERLOAD_LEVEL_EDITOR cr = j_color["r"].GetInt(255); cg = j_color["g"].GetInt(255); cb = j_color["b"].GetInt(255); if (count < 4) { color.Add(Color.FromArgb(cr, cg, cb)); } count += 1; #else cr = j_color["r"].GetInt(255); cg = j_color["g"].GetInt(255); cb = j_color["b"].GetInt(255); color.Add(new Vector3((float)cr / 255.0f, (float)cg / 255.0f, (float)cb / 255.0f)); #endif } #if OVERLOAD_LEVEL_EDITOR for (int i = color.Count; i < NUM_COLORS; i++) { color.Add(Color.White); } #endif smooth_angle_same = root["smooth_same"].GetInt(smooth_angle_same); smooth_angle_diff = root["smooth_diff"].GetInt(smooth_angle_diff); }
public DLight(DLight src) { Copy(src); }
private void gl_custom_Paint(object sender, PaintEventArgs e) { if (!m_gl_loaded) { return; } // GL Setup gl_custom.MakeCurrent(); GL.ClearColor(GLView.C_bg); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Viewport(0, 0, (int)m_control_sz.X, (int)m_control_sz.Y); // Perspective mode GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); m_persp_mat = Matrix4.CreatePerspectiveFieldOfView(Utility.RAD_45 * 1.0f, m_control_sz.X / m_control_sz.Y, 0.3f, 2000f); m_persp_mat2 = Matrix4.CreatePerspectiveFieldOfView(Utility.RAD_45 * 1.0f, m_control_sz.X / m_control_sz.Y, 0.3f, 2000f); GL.LoadMatrix(ref m_persp_mat); // Camera position Vector3 cam_pos = Vector3.Transform(Vector3.UnitZ * m_cam_distance, Matrix4.CreateRotationX(m_cam_angles.X) * Matrix4.CreateRotationY(m_cam_angles.Y)); m_cam_mat = Matrix4.LookAt(cam_pos, Vector3.Zero, Vector3.UnitY); Vector3 cam_pos2 = Vector3.Transform(Vector3.UnitZ * m_cam_distance * 1.0f, Matrix4.CreateRotationX(m_cam_angles.X) * Matrix4.CreateRotationY(m_cam_angles.Y)); m_cam_mat2 = Matrix4.LookAt(cam_pos2, Vector3.Zero, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref m_cam_mat); GL.Scale(1f, 1f, -1f); // Draw the grid if (m_view_mode == DViewMode.WIRE) { GL.Disable(EnableCap.DepthTest); } GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.Texture2D); GL.CallList(GL_GRID); // Rotate the decal to be XY for viewing (XZ is better for editing) GL.Rotate(-90, Vector3.UnitX); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.PolygonOffsetFill); GL.Enable(EnableCap.PolygonOffsetLine); GL.PolygonOffset(1f, 1f); if (m_view_mode != DViewMode.WIRE) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); if (m_view_mode == DViewMode.TEXTURE) { GL.Enable(EnableCap.Texture2D); } } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.Disable(EnableCap.Lighting); } if (m_decal_loaded) { GL.CallList(GL_DECAL); } GL.Disable(EnableCap.PolygonOffsetLine); GL.Disable(EnableCap.PolygonOffsetFill); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.Texture2D); if (m_decal_loaded) { // Lights for (int i = 0; i < DMesh.NUM_LIGHTS; i++) { if (m_active_dmesh.light[i].enabled) { DLight dl = m_active_dmesh.light[i]; if (i == m_selected_light) { GL.Color3(Color.GreenYellow); } else { GL.Color3(Color.LightYellow); } GL.PushMatrix(); GL.Translate(dl.position); GL.CallList(GL_LIGHT); if (dl.style == LightStyle.SPOT) { var light_rotation = dl.rotation; GL.MultMatrix(ref light_rotation); GL.CallList(GL_LIGHT_CONE); } GL.PopMatrix(); } } } if (m_selected_face > -1) { // Selected face GL.Disable(EnableCap.DepthTest); GL.CallList(GL_SELECTED); } if (m_show_vert_normals) { GL.Disable(EnableCap.DepthTest); GL.CallList(GL_VERT_NORMALS); } GL.End(); gl_custom.SwapBuffers(); }