Beispiel #1
0
        private void lstTextures_SelectedValueChanged(object sender, EventArgs e)
        {
            if (_selectedTexture != null)
            {
                _selectedTexture.Selected = false;
            }

            if ((_targetObject = _selectedTexture = lstTextures.SelectedItem as MDL0TextureNode) != null)
            {
                _selectedTexture.Selected = true;
            }

            if (SelectedTextureChanged != null)
            {
                SelectedTextureChanged(this, null);
            }

            if (!_updating)
            {
                if (RenderStateChanged != null)
                {
                    RenderStateChanged(this, null);
                }
            }
        }
Beispiel #2
0
        private void lstTextures_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            MDL0TextureNode tref = lstTextures.Items[e.Index] as MDL0TextureNode;

            tref.Enabled = e.NewValue == CheckState.Checked;

            if (!_updating)
            {
                if (RenderStateChanged != null)
                {
                    RenderStateChanged(this, null);
                }
            }
        }
Beispiel #3
0
        public void LoadModel(MDL0Node model)
        {
            model.Populate();
            model._renderAttribs._renderBones     = false;
            model._renderAttribs._renderPolygons  = true;
            model._renderAttribs._renderWireframe = false;
            model._renderAttribs._renderVertices  = false;
            model.ApplyCHR(null, 0);
            model.ApplySRT(null, 0);

            if (UseExceptions)
            {
                foreach (string texname in TexturesToDisable)
                {
                    MDL0TextureNode tex = model.TextureGroup.FindChild(texname, false) as MDL0TextureNode;
                    if (tex != null)
                    {
                        tex.Enabled = false;
                    }
                }
            }

            modelPanel1.ClearAll();
            modelPanel1.AddTarget((IRenderedObject)model);

            if (UseExceptions && PolygonsToDisable.ContainsKey(_charString))
            {
                foreach (int polygonNum in PolygonsToDisable[_charString])
                {
                    MDL0ObjectNode poly = model.PolygonGroup.FindChild("polygon" + polygonNum, false) as MDL0ObjectNode;
                    if (poly != null)
                    {
                        poly.IsRendering = false;
                    }
                }
            }

            Box     box = model.GetBox();
            Vector3 min = box.Min, max = box.Max;

            if (ZoomOut)
            {
                min._x += 20;
                max._x -= 20;
            }
            modelPanel1.SetCamWithBox(min, max);
        }
        public void LoadModel(MDL0Node model)
        {
            model.Populate();
            model.ResetToBindState();

            if (UseExceptions)
            {
                foreach (string texname in TexturesToDisable)
                {
                    ResourceNode textureGroup = model.TextureGroup;
                    if (textureGroup != null)
                    {
                        MDL0TextureNode tex = textureGroup.FindChild(texname, false) as MDL0TextureNode;
                        if (tex != null)
                        {
                            tex.Enabled = false;
                        }
                    }
                }
            }

            modelPanel1.ClearAll();
            modelPanel1.AddTarget((IRenderedObject)model);

            if (UseExceptions && PolygonsToDisable.ContainsKey(_charString))
            {
                foreach (string polygonNum in PolygonsToDisable[_charString])
                {
                    MDL0ObjectNode poly = model.PolygonGroup.FindChild(polygonNum, false) as MDL0ObjectNode;
                    if (poly != null)
                    {
                        poly.IsRendering = false;
                    }
                }
            }

            Box     box = model.GetBox();
            Vector3 min = box.Min, max = box.Max;

            if (ZoomOut)
            {
                min._x += 20;
                max._x -= 20;
            }
            modelPanel1.SetCamWithBox(min, max);
        }
        public void Render(GLCamera cam, bool renderBG)
        {
            cam.LoadProjection();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Color4(Color.White);
            GL.Enable(EnableCap.Texture2D);

            float
                halfW = (float)Width / 2.0f,
                halfH = (float)Height / 2.0f;

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Texture);
            GL.LoadIdentity();

            if (renderBG)
            {
                GL.PushAttrib(AttribMask.TextureBit);

                GLTexture bgTex = TKContext.FindOrCreate <GLTexture>("TexBG", GLTexturePanel.CreateBG);
                bgTex.Bind();

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                float
                    s = (float)Width / (float)bgTex.Width,
                    t = (float)Height / (float)bgTex.Height;

                GL.Begin(BeginMode.Quads);

                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex2(-halfW, -halfH);
                GL.TexCoord2(s, 0.0f);
                GL.Vertex2(halfW, -halfH);
                GL.TexCoord2(s, t);
                GL.Vertex2(halfW, halfH);
                GL.TexCoord2(0.0f, t);
                GL.Vertex2(-halfW, halfH);

                GL.End();

                GL.PopAttrib();
            }

            if (Tex0 == null)
            {
                return;
            }
            Tex0.Prepare(_targetMatRef, -1);
            GLTexture texture = GLTex;

            if (texture == null || texture._texId <= 0)
            {
                return;
            }

            MDL0TextureNode.ApplyGLTextureParameters(_targetMatRef);

            //These are used to match up the UV overlay to the texture underneath
            Vector2 topLeft     = new Vector2();
            Vector2 bottomRight = new Vector2();

            float texWidth  = texture.Width;
            float texHeight = texture.Height;

            float tAspect = (float)texWidth / texHeight;
            float wAspect = (float)Width / Height;

            float[] texCoord = new float[8];

            //These are used to compensate for padding added on an axis
            float xCorrect = 1.0f, yCorrect = 1.0f;

            if (tAspect > wAspect)
            {
                //Texture is wider, use horizontal fit
                //X touches the edges of the window, Y has top and bottom padding

                //X
                texCoord[0] = texCoord[6] = 0.0f;
                texCoord[2] = texCoord[4] = 1.0f;

                //Y
                texCoord[1] = texCoord[3] = (yCorrect = tAspect / wAspect) / 2.0f + 0.5f;
                texCoord[5] = texCoord[7] = 1.0f - texCoord[1];

                bottomRight = new Vector2(halfW, (((float)Height - ((float)Width / texWidth * texHeight)) / (float)Height / 2.0f - 0.5f) * (float)Height);
                topLeft     = new Vector2(-halfW, -bottomRight._y);
            }
            else
            {
                //Window is wider, use vertical fit
                //Y touches the edges of the window, X has left and right padding

                //Y
                texCoord[1] = texCoord[3] = 1.0f;
                texCoord[5] = texCoord[7] = 0.0f;

                //X
                texCoord[2] = texCoord[4] = (xCorrect = wAspect / tAspect) / 2.0f + 0.5f;
                texCoord[0] = texCoord[6] = 1.0f - texCoord[2];

                bottomRight = new Vector2(1.0f - (((float)Width - ((float)Height / texHeight * texWidth)) / Width / 2.0f - 0.5f) * (float)Width, -halfH);
                topLeft     = new Vector2(-bottomRight._x, halfH);
            }

            //Apply the texcoord bind transform first
            TextureFrameState state = _targetMatRef._bindState;

            GL.MultMatrix((float *)&state._transform);

            //Translate the texture coordinates to match where the user dragged the camera
            //Divide by width and height to convert window units (0 to w, 0 to h) to texcoord units (0 to 1)
            //Then multiply by the correction value if the window is bigger than the texture on an axis
            Vector3 point = cam.GetPoint();

            GL.Translate(point._x / Width * xCorrect, -point._y / Height * yCorrect, 0);

            //Now to scale the texture after translating.
            //The scale origin is the top left of the texture on the window (not of the window itself),
            //so we need to translate the center of the texture to that origin,
            //scale it up or down, then translate it back to where it was.
            OpenTK.Vector3 trans = new OpenTK.Vector3(-topLeft._x / Width * xCorrect, topLeft._y / Height * yCorrect, 0.0f);
            GL.Translate(trans);
            GL.Scale((OpenTK.Vector3)cam._scale);
            GL.Translate(-trans);

            //Bind the material ref's texture
            GL.BindTexture(TextureTarget.Texture2D, texture._texId);

            //Draw a quad across the screen and render the texture with the calculated texcoords
            GL.Begin(BeginMode.Quads);

            GL.TexCoord2(texCoord[0], texCoord[1]);
            GL.Vertex2(-halfW, -halfH);
            GL.TexCoord2(texCoord[2], texCoord[3]);
            GL.Vertex2(halfW, -halfH);
            GL.TexCoord2(texCoord[4], texCoord[5]);
            GL.Vertex2(halfW, halfH);
            GL.TexCoord2(texCoord[6], texCoord[7]);
            GL.Vertex2(-halfW, halfH);

            GL.End();
            GL.Disable(EnableCap.Texture2D);

            //Now load the camera transform and draw the UV overlay over the texture
            cam.LoadModelView();

            //Color the lines limegreen, a bright color that probably won't be in a texture
            GL.Color4(Color.LimeGreen);

            Vector2 mdlScale = new Vector2(bottomRight._x - topLeft._x, bottomRight._y - topLeft._y);

            GL.Translate(topLeft._x, topLeft._y, 0.0f);
            GL.Scale(mdlScale._x, mdlScale._y, 1.0f);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.LineWidth(1);

            //Render texture coordinates as vertex points
            foreach (RenderInfo info in _renderInfo)
            {
                info.PrepareStream();
            }
        }
Beispiel #6
0
        public override ResourceNode Duplicate(bool changeName)
        {
            if (_resource.Parent == null)
            {
                return(null);
            }

            string tempPath = Path.GetTempFileName();

            _resource.Export(tempPath);
            // Initialize node in a way that will not cause crashes
            ResourceNode rNode2;

            switch (Resource.ResourceFileType)
            {
            case ResourceType.MDL0Color:
                rNode2 = new MDL0ColorNode();
                break;

            case ResourceType.MDL0UV:
                rNode2 = new MDL0UVNode();
                break;

            case ResourceType.MDL0Material:
                rNode2 = new MDL0MaterialNode();
                break;

            case ResourceType.MDL0Shader:
                rNode2 = new MDL0ShaderNode();
                break;

            case ResourceType.MDL0Texture:
                rNode2 = new MDL0TextureNode();
                break;

            case ResourceType.MDL0Normal:
                rNode2 = new MDL0NormalNode();
                break;

            case ResourceType.MDL0Bone:
                rNode2 = new MDL0BoneNode();
                break;

            case ResourceType.MDL0Vertex:
                rNode2 = new MDL0VertexNode();
                break;

            default:
                throw new NotSupportedException("Unsupported type for MDL0 Duplication");
            }

            rNode2._name = _resource.Name;
            rNode2.Replace(tempPath);

            if (rNode2 == null)
            {
                MessageBox.Show("The node could not be duplicated correctly.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(null);
            }

            // Remove the node from the parent temporarily
            rNode2.Remove();

            // Set the name programatically (based on Windows' implementation)
            int index = _resource.Index;
            int n     = 0;

            if (changeName)
            {
                while (_resource.Parent.FindChildrenByName(rNode2.Name).Length >= 1)
                {
                    // Get the last index of the last duplicated node in order to place it after that one
                    index = Math.Max(index, _resource.Parent.FindChildrenByName(rNode2.Name).Last().Index);
                    // Set the name based on the number of duplicate nodes found
                    rNode2.Name = $"{_resource.Name} ({++n})";
                }
            }

            // Place the node in the same containing parent, after the last duplicated node.
            _resource.Parent.InsertChild(rNode2, true, index + 1);

            // Update name again in order to refresh things that need refreshing when name is updated
            rNode2.OnRenamed();

            return(rNode2);
        }