示例#1
0
        //--------------------------------
        private void WalkNodeHierarchy(TreeNodeAdv parentTreeNode, ModelNode node)
        {
            // add the current node to the tree.
            TreeNodeAdv curTreeNode = new TreeNodeAdv(node.Name);

            parentTreeNode.Nodes.Add(curTreeNode);

            // now add mesh instances to the tree.
            int meshInstCount = node.MeshInstCount;

            for (int i = 0; i < meshInstCount; ++i)
            {
                // add the instance.
                MeshInst    inst        = node.GetMeshInst(i);
                TreeNodeAdv curMeshNode = new TreeNodeAdv("< mesh >");
                curTreeNode.Nodes.Add(curMeshNode);

                // add the instance's ranges.
                Mesh mesh = inst.Mesh;
                for (int j = 0; j < inst.RangeCount; ++j)
                {
                    // get the range info.
                    RangeInfo range;
                    if (!mesh.GetRange(out range, j))
                    {
                        continue;
                    }

                    // get the material assignend to that range.
                    Material material = inst.GetMaterial(j);
                    if (material == null)
                    {
                        continue;
                    }

                    // add the name of the range.
                    TreeNodeAdv curRangeNode = new TreeNodeAdv(range.Name);
                    curMeshNode.Nodes.Add(curRangeNode);

                    // add the range's material.
                    TreeNodeAdv curMatNode = new TreeNodeAdv(material.Name);
                    curRangeNode.Nodes.Add(curMatNode);

                    // add statistics.
                    TreeNodeAdv curTriCountNode = new TreeNodeAdv(range.Count.ToString() + " tris");
                    curRangeNode.Nodes.Add(curTriCountNode);
                }
            }

            // recurse children.
            int childCount = node.ChildCount;

            for (int i = 0; i < childCount; ++i)
            {
                WalkNodeHierarchy(curTreeNode, node.GetChild(i));
            }
        }
示例#2
0
        //-----------------------
        public void Paint(MeshInst meshInst, int rangeIdx, uint[] triangleMask, PaintMode paintMode)
        {
            if (meshInst == null)
            {
                return;
            }

            Mesh mesh = meshInst.Mesh;

            if (mesh == null)
            {
                return;
            }

            // get the material associated with the meshInst's range.
            Material material = meshInst.GetMaterial(rangeIdx);

            if (material == null)
            {
                return;
            }

            // if the material isn't ubertextured, skip it.
            if (!material.Ubertextured)
            {
                return;
            }

            // determine if the current range and the paint frustum
            // intersect.
            if (!_maskCamera.Frustum.IsOBoxInside(meshInst.GetRangeOBox(rangeIdx)))
            {
                return;
            }

            // configure the ubertexture renderer for the current material's
            // targets.
            UberTexture uberTexture = new UberTexture(material.GetPass(0).UberTexture);

            if (uberTexture == null)
            {
                return;
            }

            _target = uberTexture;

            // get the inverse of the mesh instance's transform.  This is
            // so we can move the cameras into the mesh instance's local
            // space for culling and rasterization purposes.
            Matrix invInstXForm = new Matrix();

            if (!meshInst.Transform.Inverse(out invInstXForm))
            {
                return;
            }

            // get the source camera's transform.
            Matrix sourceCamXForm = new Matrix(_sourceCamera.Rotation, _sourceCamera.Position);
            Matrix maskCamXForm   = new Matrix(_maskCamera.Rotation, _maskCamera.Position);

            sourceCamXForm = invInstXForm * sourceCamXForm;
            maskCamXForm   = invInstXForm * maskCamXForm;

            // build cameras that are local to the mesh instance.
            Camera localSourceCamera = new Camera(sourceCamXForm.Translate, sourceCamXForm.Rotate,
                                                  _sourceCamera.Projection);
            Camera localMaskCamera = new Camera(maskCamXForm.Translate, maskCamXForm.Rotate,
                                                _maskCamera.Projection);

            // set the paint targets.
            _rasterizer.RenderTarget = _target;

            // set the camera info.
            _rasterizer.SetVertexConstants(0, localSourceCamera.ViewProjMatrix);
            _rasterizer.SetVertexConstants(4, localMaskCamera.ViewProjMatrix);

            // set the blending mode to accumulate.
            float blendingMode = 1.0f;

            if (_maskPaintMode == MaskMode.Subtract)
            {
                blendingMode = 0.0f;
            }

            // if the paint mode is 'fill' then disable the per-pixel clip.
            float perPixelClip = 1.0f;

            if (paintMode == PaintMode.Fill)
            {
                perPixelClip = 0.0f;
            }

            // set the mask-only value.
            float maskValue = 0.0f;

            if (paintMode == PaintMode.Mask)
            {
                maskValue = 1.0f;
            }

            // setup the shader modes.
            _rasterizer.SetFragmentConstant(0, new Vector4(blendingMode, perPixelClip, maskValue, 0.0f));

            // set the camera's rotation for normals.
            Matrix cameraRot = new Matrix(localSourceCamera.Rotation, new Vector3(0.0f, 0.0f, 0.0f));

            _rasterizer.SetFragmentConstants(1, cameraRot);

            // now grab the mesh's vertices and throw them at the
            // uber-texture renderer.
            uint triCount = CalculateVisibleTriangles(localMaskCamera, meshInst.Mesh, rangeIdx);

            // now render the visible triangles.
            _rasterizer.RenderTriangleList(meshInst.Mesh.VertexBuffer, _visibleTriangles,
                                           0, 3 * triCount);
        }