public void RenderBones() { if (VBN != null) { RenderTools.DrawVBN(VBN); } if (BCH != null) { foreach (BCH_Model mo in BCH.Models.Nodes) { RenderTools.DrawVBN(mo.skeleton); } } if (BFRES != null) { foreach (var mo in BFRES.models) { RenderTools.DrawVBN(mo.skeleton); } } if (DAT_MELEE != null) { RenderTools.DrawVBN(DAT_MELEE.bones); } }
public void Draw() { // first calcuate the point and draw a point if (IsSelected) { GL.Color3(Color.Red); } else { GL.Color3(Color.GreenYellow); } Vector3 pos_c = Vector3.Transform(Vector3.Zero, transform); RenderTools.drawCube(pos_c, .1f); // now draw line between parent GL.Color3(Color.LightBlue); GL.LineWidth(2f); GL.Begin(PrimitiveType.Lines); if (Parent != null && Parent is Bone) { Vector3 pos_p = Vector3.Transform(Vector3.Zero, ((Bone)Parent).transform); GL.Vertex3(pos_c); GL.Color3(Color.Blue); GL.Vertex3(pos_p); } GL.End(); }
public void RenderBones() { if (VBN != null) { RenderTools.DrawVBN(VBN); } if (Bch != null) { foreach (BCH_Model mo in Bch.Models.Nodes) { RenderTools.DrawVBN(mo.skeleton); } } if (Bfres != null) { foreach (var mo in Bfres.models) { RenderTools.DrawVBN(mo.skeleton); } } if (DatMelee != null) { RenderTools.DrawVBN(DatMelee.bones); } }
private void RenderTexture(GLControl glControl1, NUT nut) { if (nut == null) { return; } glControl1.MakeCurrent(); GL.Viewport(glControl1.ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.White); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); foreach (NUT.NUD_Texture tex in nut.textures) { RenderTools.DrawTexturedQuad(nut.draw[tex.id], tex.width, tex.height, true, true, true, true, false, true); } glControl1.SwapBuffers(); }
public static void DrawPoint(GeneralPoint p) { GL.LineWidth(2); Vector3 pos = p.useStartPos ? p.startPos : new Vector3(p.x, p.y, p.z); GL.Color3(Color.Red); RenderTools.drawCubeWireframe(pos, 3); }
public static void SetCameraFromSTPRM(ParamFile stprm) { if (stprm != null) { float fov = (float)RenderTools.GetValueFromParamFile(stprm, 0, 0, 6); Runtime.fov = fov * ((float)Math.PI / 180.0f); Runtime.renderDepth = (float)RenderTools.GetValueFromParamFile(stprm, 0, 0, 77); } }
public ModelViewport() { InitializeComponent(); Camera = new Camera(); FilePath = ""; Text = "Model Viewport"; CalculateLightSource(); MeshList.Dock = DockStyle.Right; MeshList.MaximumSize = new Size(300, 2000); MeshList.Size = new Size(300, 2000); AddControl(MeshList); AnimList.Dock = DockStyle.Left; AnimList.MaximumSize = new Size(300, 2000); AnimList.Size = new Size(300, 2000); AddControl(AnimList); LVDList.Dock = DockStyle.Left; LVDList.MaximumSize = new Size(300, 2000); AddControl(LVDList); LVDList.lvdEditor = LVDEditor; LVDEditor.Dock = DockStyle.Right; LVDEditor.MaximumSize = new Size(300, 2000); AddControl(LVDEditor); VertexTool.Dock = DockStyle.Left; VertexTool.MaximumSize = new Size(300, 2000); AddControl(VertexTool); VertexTool.vp = this; ACMDEditor = new ACMDPreviewEditor(); ACMDEditor.Owner = this; ACMDEditor.Dock = DockStyle.Right; ACMDEditor.updateCrcList(); AddControl(ACMDEditor); HitboxList = new HitboxList(); HitboxList.Dock = DockStyle.Right; AddControl(HitboxList); HurtboxList = new HurtboxList(); HurtboxList.Dock = DockStyle.Right; VariableViewer = new VariableList(); VariableViewer.Dock = DockStyle.Right; LVD = new Smash_Forge.LVD(); ViewComboBox.SelectedIndex = 0; draw = MeshList.treeView1.Nodes; RenderTools.Setup(); }
private void RenderTexture(bool justRenderAlpha = false) { if (!tabControl1.SelectedTab.Text.Equals("Textures")) { return; } // Get the selected NUT texture. NutTexture nutTexture = null; int displayTexture = 0; if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0) { int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash; // Display dummy textures from resources. if (Enum.IsDefined(typeof(NUD.DummyTextures), hash)) { displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash]; } else { foreach (NUT n in Runtime.TextureContainers) { if (n.draw.ContainsKey(hash)) { n.getTextureByID(hash, out nutTexture); displayTexture = n.draw[hash]; break; } } } } if (justRenderAlpha) { texAlphaGlControl.MakeCurrent(); GL.Viewport(texAlphaGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true); //RenderTools.DrawNudMaterialSphere(currentMaterialList[currentMatIndex]); texAlphaGlControl.SwapBuffers(); } else { texRgbGlControl.MakeCurrent(); GL.Viewport(texRgbGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1); //RenderTools.DrawNudMaterialSphere(materials[0]); texRgbGlControl.SwapBuffers(); } if (!Runtime.shaders["Texture"].HasCheckedCompilation) { Runtime.shaders["Texture"].DisplayCompilationWarnings("Texture"); } }
private void RenderTexture(bool justRenderAlpha = false) { if (!tabControl1.SelectedTab.Text.Equals("Textures")) { return; } // Get the selected NUT texture. NutTexture nutTexture = null; int displayTexture = 0; if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0) { int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash; // Display dummy textures from resources. if (Enum.IsDefined(typeof(NUD.DummyTextures), hash)) { displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash]; } else { foreach (NUT n in Runtime.TextureContainers) { if (n.glTexByHashId.ContainsKey(hash)) { n.getTextureByID(hash, out nutTexture); displayTexture = n.glTexByHashId[hash]; break; } } } } if (justRenderAlpha) { texAlphaGlControl.MakeCurrent(); GL.Viewport(texAlphaGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true); texAlphaGlControl.SwapBuffers(); } else { texRgbGlControl.MakeCurrent(); GL.Viewport(texRgbGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1); Bitmap image = FramebufferTools.ReadFrameBufferPixels(0, FramebufferTarget.Framebuffer, texRgbGlControl.Width, texRgbGlControl.Height); image.Save(MainForm.executableDir + "\\image.png"); texRgbGlControl.SwapBuffers(); } if (!Runtime.shaders["Texture"].HasCheckedCompilation) { Runtime.shaders["Texture"].DisplayProgramStatus("Texture"); } }
public int CheckControl(Ray r) { Vector3 pos_c = Vector3.Transform(Vector3.Zero, transform); if (RenderTools.intersectCircle(pos_c, 2f, 30, r.p1, r.p2)) { return(1); } return(-1); }
private static Vector3 CreateFogColorFromFogSet(ParamFile lightSet, int i) { float hue = (float)RenderTools.GetValueFromParamFile(lightSet, 2, 1 + i, 0); float saturation = (float)RenderTools.GetValueFromParamFile(lightSet, 2, 1 + i, 1); float value = (float)RenderTools.GetValueFromParamFile(lightSet, 2, 1 + i, 2); float fogR = 0.0f, fogB = 0.0f, fogG = 0.0f; ColorTools.HSV2RGB(hue, saturation, value, out fogR, out fogG, out fogB); Vector3 color = new Vector3(fogR, fogG, fogB); return(color); }
public NUDMaterialEditor(NUD.Polygon p) { InitializeComponent(); currentPolygon = p; currentMaterialList = p.materials; Init(); FillForm(); matsComboBox.SelectedIndex = 0; // The dummy textures will be used later. RenderTools.Setup(); }
public void Render(Matrix4 view) { if (b == null) return; Matrix4 mat = b.transform; Vector3 center = Vector3.Transform(Vector3.Zero, mat); Vector3 point; hit = false; bool _hiX = false; bool _hiY = false; bool _hiZ = false; if (RenderTools.CheckSphereHit(center, 2, VBNViewport.p1, VBNViewport.p2, out point)) { hit = true; VBNViewport.LineSphereIntersect(VBNViewport.p1, VBNViewport.p2, center, 2, out point); Vector3 angle = Angles(Vector3.Transform(point, b.invert)) * new Vector3(180f / (float)Math.PI); angle.X = Math.Abs(angle.X); angle.Y = Math.Abs(angle.Y); angle.Z = Math.Abs(angle.Z); //Console.WriteLine(angle.ToString()); float _axisSnapRange = 7f; if (Math.Abs(angle.Y - 90.0f) <= _axisSnapRange) _hiX = true; else if (angle.X >= (180.0f - _axisSnapRange) || angle.X <= _axisSnapRange) _hiY = true; else if (angle.Y >= (180.0f - _axisSnapRange) || angle.Y <= _axisSnapRange) _hiZ = true; } GL.PushMatrix(); GL.MultMatrix(ref mat); GL.Color3(_hiX ? Color.Yellow : Color.Green); GL.LineWidth(2); RenderTools.drawCircleOutline(Vector3.Zero, 2, 25); GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f); GL.Color3(_hiY ? Color.Yellow : Color.Red); RenderTools.drawCircleOutline(Vector3.Zero, 2, 25); GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f); GL.Color3(_hiZ ? Color.Yellow : Color.Blue); RenderTools.drawCircleOutline(Vector3.Zero, 2, 25); GL.PopMatrix(); }
private void RenderMaterialPreview(NUD.Material material) { if (!tabControl1.SelectedTab.Text.Equals("Textures")) { return; } GL.Viewport(texAlphaGlControl.ClientRectangle); RenderTools.DrawNudMaterialSphere(material); texRgbGlControl.SwapBuffers(); if (!Runtime.shaders["Texture"].HasCheckedCompilation) { Runtime.shaders["Texture"].DisplayProgramStatus("Texture"); } }
private static DirectionalLight CreateDirectionalLightFromLightSet(ParamFile lightSet, int lightNumber, string name) { bool enabled = (uint)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 1) == 1; float hue = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 2); float saturation = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 3); float value = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 4); float rotX = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 5); float rotY = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 6); float rotZ = (float)RenderTools.GetValueFromParamFile(lightSet, 1, lightNumber, 7); DirectionalLight newLight = new DirectionalLight(hue, saturation, value, 0, 0, 0, rotX, rotY, rotZ, name); newLight.enabled = enabled; // doesn't render properly for some stages return(newLight); }
public static void DrawShape(DamageShape s) { GL.LineWidth(2); GL.Color4(Color.FromArgb(128, Color.Yellow)); Vector3 sPos = s.useStartPos ? s.startPos : new Vector3(0, 0, 0); Vector3 pos = new Vector3(s.x, s.y, s.z); Vector3 posd = new Vector3(s.dx, s.dy, s.dz); if (s.type == 2) { RenderTools.drawSphere(sPos + pos, s.radius, 24); } if (s.type == 3) { RenderTools.drawCylinder(sPos + pos, sPos + pos + posd, s.radius); } }
public static void DrawEnemySpawners() { GL.LineWidth(2); foreach (EnemyGenerator c in Runtime.TargetLVD.enemySpawns) { GL.Color4(Color.FromArgb(200, Color.Fuchsia)); foreach (EnmSection s in c.sections) { RenderTools.drawCubeWireframe(new Vector3(s.x, s.y, s.z), 3); } GL.Color4(Color.FromArgb(200, Color.Yellow)); foreach (EnmSection s in c.sections2) { RenderTools.drawCubeWireframe(new Vector3(s.x, s.y, s.z), 3); } } }
public void RenderBones() { if (VBN != null) { RenderTools.DrawVBN(VBN); } if (BCH != null) { foreach (BCH_Model mo in BCH.Models.Nodes) { RenderTools.DrawVBN(mo.skeleton); } } if (dat_melee != null) { RenderTools.DrawVBN(dat_melee.bones); } }
private void RenderTexture() { if (!_loaded || glControl1 == null) { return; } glControl1.MakeCurrent(); GL.Viewport(glControl1.ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); GL.ClearColor(Color.Black); if (textureList.SelectedItem == null) { glControl1.SwapBuffers(); return; } GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); int width = ((NUT_Texture)textureList.SelectedItem).Width; int height = ((NUT_Texture)textureList.SelectedItem).Height; int texture = NUT.draw[((NUT_Texture)textureList.SelectedItem).HASHID]; bool alphaOverride = renderAlpha && !renderR && !renderG && !renderB; RenderTools.DrawTexturedQuad(texture, width, height, renderR, renderG, renderB, renderAlpha, alphaOverride, preserveAspectRatio); glControl1.SwapBuffers(); if (!Runtime.hasCheckedTexShaderCompilation) { Runtime.shaders["Texture"].displayCompilationWarning("Texture"); Runtime.hasCheckedTexShaderCompilation = true; } }
public void Draw() { Vector3 pos_c = Vector3.Transform(Vector3.Zero, transform); // first calcuate the point and draw a point if (IsSelected) { /*GL.Color3(Color.Red); * RenderTools.drawCircleOutline(pos_c, 2f, 30, Matrix4.CreateRotationX(0)); * GL.Color3(Color.Green); * RenderTools.drawCircleOutline(pos_c, 2f, 30, Matrix4.CreateRotationX(rot90)); * GL.Color3(Color.Gold); * RenderTools.drawCircleOutline(pos_c, 2f, 30, Matrix4.CreateRotationY(rot90));*/ GL.Color3(Color.Red); } else { GL.Color3(Color.GreenYellow); } RenderTools.drawCube(pos_c, .1f); // now draw line between parent GL.Color3(Color.LightBlue); GL.LineWidth(2f); GL.Begin(PrimitiveType.Lines); if (Parent != null && Parent is Bone) { Vector3 pos_p = Vector3.Transform(Vector3.Zero, ((Bone)Parent).transform); GL.Vertex3(pos_c); GL.Color3(Color.Blue); GL.Vertex3(pos_p); } GL.End(); }
public static void SetLightsFromLightSetParam(ParamFile lightSet) { if (lightSet != null) { // stage diffuse for (int i = 0; i < stageDiffuseLightSet.Length; i++) { stageDiffuseLightSet[i] = CreateDirectionalLightFromLightSet(lightSet, 4 + i, "Stage " + i); } // stage fog for (int i = 0; i < stageFogSet.Length; i++) { stageFogSet[i] = CreateFogColorFromFogSet(lightSet, i); } // character diffuse { float difHue = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 29); float difSaturation = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 30); float difIntensity = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 31); float ambHue = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 33); float ambSaturation = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 34); float ambIntensity = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 35); float rotX = (float)RenderTools.GetValueFromParamFile(lightSet, 1, 4, 5); float rotY = (float)RenderTools.GetValueFromParamFile(lightSet, 1, 4, 6); float rotZ = (float)RenderTools.GetValueFromParamFile(lightSet, 1, 4, 7); diffuseLight = new DirectionalLight(difHue, difSaturation, difIntensity, ambHue, ambSaturation, ambIntensity, 0, 0, 0, "Diffuse"); } // character diffuse 2 { diffuseLight2 = CreateDirectionalLightFromLightSet(lightSet, 0, "Diffuse2"); } // character diffuse 3 { diffuseLight3 = CreateDirectionalLightFromLightSet(lightSet, 1, "Diffuse3"); } // fresnel lighting { float hueSky = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 8); float satSky = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 9); float intensitySky = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 10); float hueGround = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 11); float satGround = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 12); float intensityGround = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 13); float skyAngle = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 14); float groundAngle = (float)RenderTools.GetValueFromParamFile(lightSet, 0, 0, 15); fresnelLight = new HemisphereFresnel(hueGround, satGround, intensityGround, hueSky, satSky, intensitySky, skyAngle, groundAngle, "Fresnel"); } } }
public void Render(VBN Skeleton) { if (!Runtime.renderHitboxes || Skeleton == null) { return; } if (Hitboxes.Count <= 0) { return; } GL.Enable(EnableCap.Blend); GL.Disable(EnableCap.CullFace); foreach (var pair in Hitboxes) { var h = pair.Value; if (Runtime.HiddenHitboxes.Contains(h.ID)) { continue; } Bone b = getBone(h.Bone, Skeleton); h.va = Vector3.TransformPosition(new Vector3(h.X, h.Y, h.Z), b.transform.ClearScale()); // Draw angle marker RenderHitboxAngles(h, Skeleton); GL.Color4(h.GetDisplayColor()); // Draw everything to the stencil buffer RenderTools.beginTopLevelStencil(); if (!h.IsSphere()) { h.va2 = new Vector3(h.X2, h.Y2, h.Z2); if (h.Bone != -1) { h.va2 = Vector3.TransformPosition(h.va2, b.transform.ClearScale()); } RenderTools.drawCylinder(h.va, h.va2, h.Size); } else { RenderTools.drawSphere(h.va, h.Size, 30); } // n factorial (n!) algorithm (NOT EFFICIENT) to draw subsequent hitboxes around each other. // Will work fine for the low amounts of hitboxes in smash4. if (Runtime.renderHitboxesNoOverlap) { // Remove the stencil for the already drawn hitboxes RenderTools.beginTopLevelAntiStencil(); foreach (var pair2 in Hitboxes.Reverse()) { if (pair2.Key == pair.Key) { break; // this only works because the list is sorted } var h2 = pair2.Value; if (!Runtime.HiddenHitboxes.Contains(h2.ID)) { Bone b2 = getBone(h2.Bone, Skeleton); var va = Vector3.TransformPosition(new Vector3(h2.X, h2.Y, h2.Z), b2.transform.ClearScale()); if (!h2.IsSphere()) { var va2 = new Vector3(h2.X2, h2.Y2, h2.Z2); if (h2.Bone != -1) { va2 = Vector3.TransformPosition(va2, b2.transform.ClearScale()); } RenderTools.drawCylinder(va, va2, h2.Size); } else { RenderTools.drawSphere(va, h2.Size, 30); } } } } if (Runtime.SelectedHitboxID == h.ID) { GL.Color4(Color.FromArgb(Runtime.hurtboxAlpha, Runtime.hurtboxColorSelected)); if (!h.IsSphere()) { RenderTools.drawWireframeCylinder(h.va, h.va2, h.Size); } else { RenderTools.drawWireframeSphere(h.va, h.Size, 10); } } // End stenciling and draw over all the stenciled bits RenderTools.endTopLevelStencilAndDraw(); } GL.Enable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); }
private void RenderRotationTool(Camera Camera, Ray Ray) { Matrix4 mat = b.transform.ClearScale(); Vector3 center = Vector3.TransformPosition(Vector3.Zero, mat); Matrix4 invTrasnform = b.transform.ClearScale().Inverted(); Vector3 point; if (state == 0) { hit = Ray.LineSphereIntersect(center, Size, out point); if (hit) { Vector3 angle = Angles(Vector3.TransformPosition(point, invTrasnform)) * new Vector3(180f / (float)Math.PI); angle.X = Math.Abs(angle.X); angle.Y = Math.Abs(angle.Y); angle.Z = Math.Abs(angle.Z); _hiX = false; _hiY = false; _hiZ = false; float _axisSnapRange = 14f; if (Math.Abs(angle.Y - 90.0f) <= _axisSnapRange) { _hiX = true; } else if (angle.X >= (180.0f - _axisSnapRange) || angle.X <= _axisSnapRange) { _hiY = true; } else if (angle.Y >= (180.0f - _axisSnapRange) || angle.Y <= _axisSnapRange) { _hiZ = true; } } if (!_hiX && !_hiZ && !_hiY) { hit = false; } } if (state == 1) { float sx = (Ray.mouse_x - PrevPoint.X) / 100; float sy = (Ray.mouse_y - PrevPoint.Y) / 100; float s = sx + sy; if (_hiX) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitX, s); } if (_hiY) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitY, s); } if (_hiZ) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitZ, s); } b.vbnParent.update(); } GL.PushMatrix(); GL.MultMatrix(ref mat); GL.Color4(0.25f, 0.25f, 0.25f, 0.2f); RenderTools.drawSphere(Vector3.Zero, Size, 25); GL.Color3(_hiZ ? Color.Yellow : Color.Green); GL.LineWidth(3); RenderTools.drawCircleOutline(Vector3.Zero, Size, 25); GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f); GL.Color3(_hiX ? Color.Yellow : Color.Red); RenderTools.drawCircleOutline(Vector3.Zero, Size, 25); GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f); GL.Color3(_hiY ? Color.Yellow : Color.Blue); RenderTools.drawCircleOutline(Vector3.Zero, Size, 25); GL.PopMatrix(); }
public void RenderScaleTool(Camera Camera, Ray Ray) { Matrix4 mat = b.transform.ClearScale(); // Matrix4.CreateTranslation(b.transform.ExtractTranslation()); Vector3 center = Vector3.TransformPosition(Vector3.Zero, mat); if (state == 0) { _hiX = false; _hiY = false; _hiZ = false; Vector3 close; if (Ray.CheckSphereHit(center, 0.5f, out close)) { _hiX = true; _hiY = true; _hiZ = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(2, 0, 0), mat), 0.5f, out close)) { _hiX = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 2, 0), mat), 0.5f, out close)) { _hiY = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 0, 2), mat), 0.5f, out close)) { _hiZ = true; } hit = true; if (!_hiX && !_hiZ && !_hiY) { hit = false; } } if (state == 1) { float sx = (Ray.mouse_x - PrevPoint.X) / 100; float sy = (Ray.mouse_y - PrevPoint.Y) / 100; float s = sx + sy; b.sca = b.sca + new Vector3(_hiX ? s : 0, _hiY ? s : 0, _hiZ ? s : 0); b.vbnParent.update(); } GL.PushMatrix(); GL.MultMatrix(ref mat); GL.LineWidth(2f); GL.Begin(PrimitiveType.Lines); GL.Color3(_hiX ? Color.Yellow : Color.Red); GL.Vertex3(0, 0, 0); GL.Vertex3(2, 0, 0); GL.Color3(_hiY ? Color.Yellow : Color.Green); GL.Vertex3(0, 0, 0); GL.Vertex3(0, 2, 0); GL.Color3(_hiZ ? Color.Yellow : Color.Blue); GL.Vertex3(0, 0, 0); GL.Vertex3(0, 0, 2); GL.End(); GL.Color3(_hiX ? Color.Yellow : Color.Red); RenderTools.drawCube(new Vector3(2, 0, 0), 0.25f); GL.Color3(_hiY ? Color.Yellow : Color.Green); RenderTools.drawCube(new Vector3(0, 2, 0), 0.25f); GL.Color3(_hiZ ? Color.Yellow : Color.Blue); RenderTools.drawCube(new Vector3(0, 0, 2), 0.25f); GL.PopMatrix(); }
public bool TrySphereHit(Vector3 sphere, float rad, out Vector3 closest) { return(RenderTools.CheckSphereHit(sphere, rad, p1, p2, out closest)); }
private void LetsDance(object sender, EventArgs e) { Control c = MainForm.Instance.GetActiveModelViewport(); if (!(c is ModelViewport)) { return; } ModelViewport view = (ModelViewport)c; view.currentMode = ModelViewport.Mode.Normal; NUT n = null; if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { n = stock_90; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { n = chr_00; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { n = chr_11; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { n = chr_13; } if (n == null) { return; } byte[] data = RenderTools.DXT5ScreenShot(view.glViewport, view.shootX, view.shootY, view.shootWidth, view.shootHeight); int id = n.Nodes.Count > 0 ? ((NutTexture)n.Nodes[0]).HashId : 0x280052B7; n.Nodes.Clear(); n.glTexByHashId.Clear(); NutTexture tex = new NutTexture(); tex.Width = view.shootWidth; tex.Height = view.shootHeight; tex.surfaces.Add(new TextureSurface()); tex.surfaces[0].mipmaps.Add(FlipDXT5(data, tex.Width, tex.Height)); tex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; tex.HashId = id; n.Nodes.Add(tex); n.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); ((MenuItem)sender).GetContextMenu().SourceControl.Invalidate(); if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { if (stock_90_loc != null) { stock_90.Save(stock_90_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { if (chr_00_loc != null) { chr_00.Save(chr_00_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { if (chr_11_loc != null) { chr_11.Save(chr_13_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { if (chr_13_loc != null) { chr_13.Save(chr_13_loc); } } }
// Rendering private void Render() { if (!render) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (Runtime.renderBackGround) { GL.Begin(PrimitiveType.Quads); GL.Color3(back1); GL.Vertex2(1.0, 1.0); GL.Vertex2(-1.0, 1.0); GL.Color3(back2); GL.Vertex2(-1.0, -1.0); GL.Vertex2(1.0, -1.0); GL.End(); } // set up the viewport projection and send it to GPU GL.MatrixMode(MatrixMode.Projection); if (glViewport.Focused && glViewport.ClientRectangle.Contains(PointToClient(Cursor.Position))) { cam.Update(); view = cam.getViewMatrix() * perspective; } cam.TrackMouse(); GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); GL.LoadMatrix(ref view); // ready to start drawing model stuff GL.MatrixMode(MatrixMode.Modelview); RenderTools.drawFloor(Matrix4.CreateTranslation(Vector3.Zero)); GL.Enable(EnableCap.Normalize); // These is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); foreach (ModelContainer m in draw) { RenderTools.DrawModel(m, view); } GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.DepthFunc(DepthFunction.Less); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Disable(EnableCap.CullFace); GL.UseProgram(0); // clear the buffer bit so the skeleton // will be drawn on top of everything GL.Clear(ClearBufferMask.DepthBufferBit); // drawing the bones foreach (ModelContainer m in draw) { if (m.vbn != null) { RenderTools.DrawVBN(m.vbn); } } GL.PopAttrib(); glViewport.SwapBuffers(); }
private void checkSelect() { if (selecting) { Vector2 m = getMouseOnViewPort(); if (!m.Equals(new Vector2(sx1, sy1))) { // select group of vertices float minx = Math.Min(sx1, m.X); float miny = Math.Min(sy1, m.Y); float width = Math.Abs(sx1 - m.X); float height = Math.Abs(sy1 - m.Y); foreach (ModelContainer con in draw) { foreach (NUD.Mesh mesh in con.nud.meshes) { foreach (NUD.Polygon poly in mesh.Nodes) { //if (!poly.IsSelected && !mesh.IsSelected) continue; int i = 0; foreach (NUD.Vertex v in poly.vertices) { poly.selectedVerts[i] = 0; Vector3 n = getScreenPoint(v.pos); if (n.X >= minx && n.Y >= miny && n.X <= minx + width && n.Y <= miny + height) { poly.selectedVerts[i] = 1; } i++; } } } } } else { // single vertex Ray r = RenderTools.createRay(view, getMouseOnViewPort()); Vector3 close = Vector3.Zero; foreach (ModelContainer con in draw) { foreach (NUD.Mesh mesh in con.nud.meshes) { foreach (NUD.Polygon poly in mesh.Nodes) { //if (!poly.IsSelected && !mesh.IsSelected) continue; int i = 0; foreach (NUD.Vertex v in poly.vertices) { if (!poly.IsSelected) { continue; } if (r.TrySphereHit(v.pos, 0.2f, out close)) { poly.selectedVerts[i] = 1; } i++; } } } } } vertexTool.refresh(); selecting = false; } }
// Rendering private void Render() { if (!render) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (Runtime.renderBackGround) { GL.Begin(PrimitiveType.Quads); GL.Color3(Runtime.back1); GL.Vertex2(1.0, 1.0); GL.Vertex2(-1.0, 1.0); GL.Color3(Runtime.back2); GL.Vertex2(-1.0, -1.0); GL.Vertex2(1.0, -1.0); GL.End(); } // set up the viewport projection and send it to GPU if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.S)) { selecting = false; if (glViewport.Focused && glViewport.ClientRectangle.Contains(PointToClient(Cursor.Position))) { cam.Update(); view = cam.getModelViewMatrix() * perspective; } cam.TrackMouse(); } else { if (OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Left) && !selecting) { selecting = true; Vector2 m = getMouseOnViewPort(); sx1 = m.X; sy1 = m.Y; } } GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); GL.LoadMatrix(ref view); // ready to start drawing model stuff GL.MatrixMode(MatrixMode.Modelview); if (Runtime.renderFloor) { RenderTools.drawFloor(); } GL.Enable(EnableCap.Normalize); // These is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); // draw renderable objects foreach (ModelContainer m in draw) { RenderTools.DrawModel(m, view); } GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.DepthFunc(DepthFunction.Less); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Disable(EnableCap.CullFace); // clear the buffer bit so the skeleton // will be drawn on top of everything GL.UseProgram(0); GL.Clear(ClearBufferMask.DepthBufferBit); // drawing the bones foreach (ModelContainer m in draw) { if (m.vbn != null) { RenderTools.DrawVBN(m.vbn); } } // Mouse selection if (selecting) { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Clear(ClearBufferMask.DepthBufferBit); if (OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { selecting = false; } Vector2 m = getMouseOnViewPort(); GL.Color3(Color.AliceBlue); GL.LineWidth(2f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); } GL.PopAttrib(); glViewport.SwapBuffers(); }
public NUDMaterialEditor() { InitializeComponent(); RenderTools.Setup(); }