Ejemplo n.º 1
0
        public Auditor( Libx42.Model model )
        {
            if( model == null )
                throw new ArgumentNullException( "model" );

            this.model = model;

            modelScore = new ModelScore( model );
        }
Ejemplo n.º 2
0
        public RawDataView( Libx42.Model model, string path )
        {
            InitializeComponent();

            this.model.Model = model;
            this.path = path;

            SetCaption( FormatPathForCaption( path ) );

            Application.Idle += new EventHandler( Application_Idle );
        }
Ejemplo n.º 3
0
        public ModelWindow( Libx42.Model model, String path )
        {
            InitializeComponent();

            this.model.Model = model;
            this.path = path;

            SetCaption( FormatPathForCaption( path ) );

            Application.Idle += new EventHandler( Application_Idle );
            Properties.Settings.Default.PropertyChanged += new PropertyChangedEventHandler( Default_PropertyChanged );
        }
Ejemplo n.º 4
0
        public ModelRenderBuffers( Scene scene, Libx42.Model model )
            : base(scene.GetService<IGraphicsDeviceService>())
        {
            if( model == null )
                throw new ArgumentNullException( "model" );

            Libx42.AnimationFlags flags = Libx42.AnimationFlags.None;

            if( model.HasNormalData )
                flags |= Libx42.AnimationFlags.IncludeNormals;

            if( model.HasTangentBasisData )
            {
                flags |= Libx42.AnimationFlags.IncludeNormals;
                flags |= Libx42.AnimationFlags.IncludeTangentBasis;
            }

            this.model = model;
            this.animBuf = model.CreateAnimationBuffer( flags );
        }
Ejemplo n.º 5
0
        public void Draw( Libx42.Lod lod )
        {
            if( lod == null )
                throw new ArgumentNullException( "lod" );
            if( vbPntb == null || vbTcCl == null ||
                ib == null || decl == null )
                throw new InvalidOperationException();
            if( lod.Owner != model.Model )
                throw new ArgumentException();

            for( int i = 0; i < lod.Groups.Count; i++ )
                Draw( lod.Groups[i] );
        }
Ejemplo n.º 6
0
        public void Draw( Libx42.Group group )
        {
            if( group == null )
                throw new ArgumentNullException( "group" );
            if( vbPntb == null || vbTcCl == null || decl == null )
                throw new InvalidOperationException();
            if( group.Owner != model.Model )
                throw new ArgumentException();

            Device dev = pn3D.Device;

            PrimitiveType primType = Helpers.ConvertToDX( group.PrimitiveType );

            if( group.Indices.IsImplicit )
            {
                dev.DrawPrimitives( primType, group.Vertices.Offset, group.PrimitiveCount );
            }
            else
            {
                dev.DrawIndexedPrimitives( primType, group.Vertices.Offset, 0,
                    group.Vertices.Count, group.Indices.Offset, group.PrimitiveCount );
            }
        }
        private void GenGroupTopology( Libx42.Group g )
        {
            Color cl;
            switch( g.PrimitiveType )
            {
            case Libx42.PrimitiveType.TriangleStrip:
                cl = Properties.Settings.Default.ModelView_TopoView_TriStripColor;
                break;

            case Libx42.PrimitiveType.TriangleFan:
                cl = Properties.Settings.Default.ModelView_TopoView_TriFanColor;
                break;

            case Libx42.PrimitiveType.TriangleList:
                cl = Properties.Settings.Default.ModelView_TopoView_TriListColor;
                break;

            default:
                topoEntries.Add( new GroupTopologyEntry() ); //place holder so indices line up
                return;
            }

            ushort[] tris = Helpers.GetTriangleIndices( g );
            Helpers.Adjacency adj = new Helpers.Adjacency( tris );
            Libx42.DataStream<Vector3> vp = modelDXData.AnimationBuffer.PositionStream.Reinterpret<Vector3>();

            GroupTopologyEntry entry = new GroupTopologyEntry();
            entry.FirstVert = topoPoints.Count;
            entry.FirstCenterVert = topoPoints.Count;

            for( int t = 0; t < adj.NumTris; t++ )
            {
                ushort i0 = (ushort)(g.Vertices.Offset + tris[t * 3 + 0]);
                ushort i1 = (ushort)(g.Vertices.Offset + tris[t * 3 + 1]);
                ushort i2 = (ushort)(g.Vertices.Offset + tris[t * 3 + 2]);

                topoPoints.Add( new LineVertex( Helpers.GetIncenter( vp[i0], vp[i1], vp[i2] ), cl ) );
            }

            entry.NumCenterVerts = topoPoints.Count - entry.FirstCenterVert;

            int[] edgeIdxMap = new int[adj.Edges.Count];

            //create center points on each edge (ToDo: collapse duplicated points away)
            for( int i = 0; i < edgeIdxMap.Length; i++ )
            {
                ushort i0 = (ushort)(g.Vertices.Offset + adj.Edges[i].First);
                ushort i1 = (ushort)(g.Vertices.Offset + adj.Edges[i].Second);

                edgeIdxMap[i] = entry.NumCenterVerts + i;
                topoPoints.Add( new LineVertex( Vector3.Lerp( vp[i0], vp[i1], 0.5F ), cl ) );
            }

            entry.NumVerts = topoPoints.Count - entry.FirstVert;

            entry.FirstBorderEdgeIndex = topoIndices.Count;

            for( int i = 0; i < adj.BorderEdges.Count; i++ )
            {
                topoIndices.Add( adj.Edges[adj.BorderEdges[i]].First );
                topoIndices.Add( adj.Edges[adj.BorderEdges[i]].Second );
            }

            entry.NumBorderEdges = (topoIndices.Count - entry.FirstBorderEdgeIndex) / 2;

            entry.FirstAdjacencyEdgeIndex = topoIndices.Count;

            #if ADJ
            for( int t = 0; t < adj.NumTris; t++ )
            {
                Helpers.Adjacency.TriEntry te = adj.Entries[t];

                for( int e = 0; e < te.AdjLength; e++ )
                {
                    Helpers.Adjacency.AdjEntry ae = adj.Values[te.AdjIndex + e];
                    //add a line from the current triangle's center,
                    //through the shared edge, to the adjacent triangle's center

                    topoIndices.Add( (ushort)t );
                    topoIndices.Add( (ushort)edgeIdxMap[ae.ThisEdge] );
                    topoIndices.Add( (ushort)edgeIdxMap[ae.OtherEdge] );
                    topoIndices.Add( (ushort)ae.OtherTriangle );
                }
            }
            #endif

            entry.NumAdjacencyEdges = (topoIndices.Count - entry.FirstAdjacencyEdgeIndex) / 2;

            if( g.PrimitiveType == Libx42.PrimitiveType.TriangleStrip )
            {
                Dictionary<int, List<ushort>> shadeIndices = new Dictionary<int, List<ushort>>();

                entry.FirstStripEdgeIndex = topoIndices.Count;

                for( int e, s = 0; s < adj.NumTris; s = e )
                {
                    ushort is0 = tris[s * 3 + 0];
                    ushort is1 = tris[s * 3 + 1];
                    ushort is2 = tris[s * 3 + 2];

                    if( is0 == is1 || is1 == is2 || is2 == is0 )
                    {
                        entry.NumDegenerates++;

                        e = s + 1;
                        continue;
                    }

                    for( e = s + 1; e < adj.NumTris; e++ )
                    {
                        ushort ie0 = tris[e * 3 + 0];
                        ushort ie1 = tris[e * 3 + 1];
                        ushort ie2 = tris[e * 3 + 2];

                        if( ie0 == ie1 || ie1 == ie2 || ie2 == ie0 )
                            break;
                    }

                    //have a strip starting at s and ending one triangle before e

                    //throw it into the shading indices list
                    int len = e - s;

                    List<ushort> shadeList;
                    if( !shadeIndices.TryGetValue( len, out shadeList ) )
                    {
                        shadeList = new List<ushort>();
                        shadeIndices.Add( len, shadeList );
                    }

                    for( int t = s; t < e; t++ )
                    {
                        shadeList.Add( tris[t * 3 + 0] );
                        shadeList.Add( tris[t * 3 + 1] );
                        shadeList.Add( tris[t * 3 + 2] );
                    }

                    //add it to the strip lines list
                    for( int t = s + 1; t < e; t++ )
                    {
                        Helpers.Adjacency.TriEntry te = adj.Entries[t];

                        for( int ie = 0; ie < te.AdjLength; ie++ )
                        {
                            Helpers.Adjacency.AdjEntry ae = adj.Values[te.AdjIndex + ie];

                            if( ae.OtherTriangle != t - 1 )
                                continue;

                            //add a line from the current triangle's center,
                            //through the shared edge, to the adjacent triangle's center

                            topoIndices.Add( (ushort)t );
                            topoIndices.Add( (ushort)edgeIdxMap[ae.ThisEdge] );
                            topoIndices.Add( (ushort)edgeIdxMap[ae.OtherEdge] );
                            topoIndices.Add( (ushort)ae.OtherTriangle );

                            break;
                        }
                    }
                }

                entry.NumStripEdges = (topoIndices.Count - entry.FirstStripEdgeIndex) / 2;

                entry.StripGroups = new StripEntry[shadeIndices.Count];

                int[] lens = new int[shadeIndices.Count];
                shadeIndices.Keys.CopyTo( lens, 0 );

                for( int i = 0; i < lens.Length; i++ )
                {
                    List<ushort> indices = shadeIndices[lens[i]];

                    entry.StripGroups[i].StripLength = lens[i];
                    entry.StripGroups[i].FirstIndex = topoIndices.Count;
                    entry.StripGroups[i].NumTriangles = indices.Count / 3;

                    topoIndices.AddRange( indices );
                }
            }

            topoEntries.Add( entry );
        }
        private int[] GetGroupInfluenceColors( Libx42.Group g, bool[] infSels, Color defaultColor, Color weightColor )
        {
            int[] ret = new int[g.Vertices.Count];

            for( int i = 0; i < g.Vertices.Count; i++ )
            {
                float totalWeight = 0;

                for( int wt = 0; wt < Libx42.VertexPosition.NumBlendWeignts; wt++ )
                {
                    int index;
                    float weight;

                    if( g.Vertices.PositionStream[i].GetBlend( wt, out index, out weight ) )
                    {
                        if( infSels[g.Influences[index].Index] )
                            totalWeight += weight;
                    }
                }

                float t = (float)Math.Pow( totalWeight, 0.75F );
                ret[i] = Helpers.Lerp( defaultColor, weightColor, t ).ToArgb();
            }

            return ret;
        }
Ejemplo n.º 9
0
        private void AddGroupNode( TreeNodeCollection dest, Libx42.Group group,
			bool addInfs )
        {
            TreeNode node = dest.Add( string.Format( "{0}: {1}", group.Index, group.SurfaceName ) );
            node.ImageIndex = 0;
            node.SelectedImageIndex = 0;
            node.Tag = group;

            if( addInfs )
                AddInfluenceNodes( node.Nodes, group.Influences, false, true, false );
        }
Ejemplo n.º 10
0
        public VisualDiff( Libx42.Model model1, Libx42.Model model2 )
        {
            if( model1 == null )
                throw new ArgumentNullException( "model1" );
            if( model2 == null )
                throw new ArgumentNullException( "model2" );

            InitializeComponent();

            this.model1.Model = model1;
            this.model2.Model = model2;

            cam.CenterOnSphere(
                Helpers.ConvertToDX( model1.BoundingSphere.Center ),
                model1.BoundingSphere.Radius );
        }
Ejemplo n.º 11
0
        internal ModelScore( Libx42.Model model )
        {
            this.model = model;

            for( int i = 0; i < model.Lods.Count; i++ )
                lodScores.Add( new LodScore( model.Lods[i] ) );
        }
Ejemplo n.º 12
0
 internal GroupScore( Libx42.Group group )
 {
     this.group = group;
 }
Ejemplo n.º 13
0
 internal GroupContext( GroupsPanel owner, Libx42.Group group )
 {
     this.owner = owner;
     this.group = group;
 }
Ejemplo n.º 14
0
 public void UpdateAnimation( Libx42.Pose pose )
 {
     animBuf.AnimateVertices( pose );
     UploadVerticesPntb();
 }
Ejemplo n.º 15
0
        public static AnimationClip FromModelClip( Libx42.AnimationClip clip )
        {
            AnimationClip ret = new AnimationClip();

            ret.Name = clip.Name;

            ret.FirstFrame = clip.FirstFrame;
            ret.LastFrame = clip.LastFrame;

            ret.IsLooping = clip.IsLoopingAnimation;

            if( clip.IsLoopingAnimation )
            {
                ret.FirstLoopingFrame = clip.LoopStart;
                ret.LastLoopingFrame = clip.LoopEnd;
            }

            ret.FrameRate = clip.FrameRate;

            return ret;
        }
Ejemplo n.º 16
0
 private string GetMatrixString( Libx42.Math.Affine a )
 {
     return string.Format( "{0:0.000}\t{1:0.0000}\t{2:0.0000}\t{3:0.0000}\n{4:0.0000}\t{5:0.0000}\t{6:0.0000}\t{7:0.0000}\n{8:0.0000}\t{9:0.0000}\t{10:0.0000}\t{11:0.0000}\n0.0000\t0.0000\t0.0000\t1.0000",
         a.c00, a.c10, a.c20, a.c30, a.c01, a.c11, a.c21, a.c31, a.c02, a.c12, a.c22, a.c32 );
 }
Ejemplo n.º 17
0
        private void AddTagNode( TreeNodeCollection dest, Libx42.Tag tag, bool addBone )
        {
            TreeNode node = dest.Add( tag.Name );
            node.ImageIndex = 3;
            node.SelectedImageIndex = 3;
            node.Tag = tag;

            if( addBone && tag.Bone != null )
                AddBoneNode( node.Nodes, tag.Bone, false, false, false, false, false );
        }
Ejemplo n.º 18
0
        private void AddInfluenceNode( TreeNodeCollection dest, Libx42.Influence inf,
			bool addBone, bool addGroups )
        {
            TreeNode node = dest.Add( string.Format( "Influence {0}", inf.Index ) );
            node.ImageIndex = 2;
            node.SelectedImageIndex = 2;
            node.Tag = inf;

            node.ToolTipText = GetMatrixString( inf.MeshToBone );

            if( addBone && inf.Bone != null )
                AddBoneNode( node.Nodes, inf.Bone, false, false, false, false, false );
            if( addGroups )
                AddGroupNodes( node.Nodes, inf.GetGroups(), false, false );
        }
Ejemplo n.º 19
0
        private void AuditGroupTopology( Libx42.Group group )
        {
            switch( group.PrimitiveType )
            {
            case Libx42.PrimitiveType.TriangleStrip:
                break;

            default:
                return;
            }

            List<int> stripLengths = new List<int>();

            Helpers.PrimitiveIterator iter = new Helpers.PrimitiveIterator( group );

            int len = 0;
            while( iter.MoveNext() )
            {
                ushort i0 = iter.Current( 0 );
                ushort i1 = iter.Current( 1 );
                ushort i2 = iter.Current( 2 );

                if( i0 == i1 || i1 == i2 || i2 == i0 )
                {
                    if( len != 0 )
                        stripLengths.Add( len );

                    len = 0;
                    continue;
                }

                len++;
            }

            float totalLengths = 0;
            for( int i = 0; i < stripLengths.Count; i++ )
                totalLengths += (float)stripLengths[i];

            items.Add( new Items.GroupStripInfo( group, stripLengths.Count, totalLengths / (float)stripLengths.Count ) );
        }
Ejemplo n.º 20
0
            public DuplicateInfluenceWarning( Libx42.Influence first,
				Libx42.Influence second )
            {
                if( first == null )
                    throw new ArgumentNullException( "first" );
                if( second == null )
                    throw new ArgumentNullException( "second" );

                Severity = Severity.Warning;
                Message = string.Format(
                    "Influence {0} is equivalent to influence {1}.",
                    first.Index, second.Index );
                TargetItem = first;
            }
Ejemplo n.º 21
0
        internal LodScore( Libx42.Lod lod )
        {
            this.lod = lod;

            for( int i = 0; i < lod.Groups.Count; i++ )
                groupScores.Add( new GroupScore( lod.Groups[i] ) );
        }
Ejemplo n.º 22
0
            public FewVertsWeightedToInfluenceWarning( Libx42.Influence influence, int numAttachedVerts )
            {
                if( influence == null )
                    throw new ArgumentNullException( "influence" );

                Severity = Severity.Warning;
                Message = string.Format(
                    "Influence {0} only has {1} vertices weighted to it.",
                    influence.Index, numAttachedVerts );
                TargetItem = influence;
            }
Ejemplo n.º 23
0
            public GroupStripInfo( Libx42.Group group, int numStrips, float avgStripLen )
            {
                if( group == null )
                    throw new ArgumentNullException( "group" );

                Severity = Severity.Info;
                Message = string.Format( "Group {0}: {1} is composed of {2} strips averaging {3:0.00} triangles long.",
                    group.Index, group.SurfaceName, numStrips, avgStripLen );
                TargetItem = group;
            }
Ejemplo n.º 24
0
 private void FillBoneSels( bool[] boneSels, Libx42.Bone bone )
 {
     for( Libx42.Bone b = bone; b != null; b = b.Parent )
         boneSels[b.Index] = true;
 }
Ejemplo n.º 25
0
 private Matrix GetBoundsMatrix( Libx42.Bone bone )
 {
     Vector3 pos = Helpers.ConvertToDX( modelDXData.Pose.BoneMatrices[bone.Index].GetColumn( 3 ) );
     return Matrix.Scaling( bone.Extent, bone.Extent, bone.Extent ) * Matrix.Translation( pos );
 }
Ejemplo n.º 26
0
        private void AddBoneNode( TreeNodeCollection dest, Libx42.Bone bone,
			bool addInfs, bool addTags, bool addParent, bool addChildren, bool expand )
        {
            TreeNode node = dest.Add( bone.Name );
            node.ImageIndex = 1;
            node.SelectedImageIndex = 1;
            node.Tag = bone;

            if( addInfs )
                AddInfluenceNodes( node.Nodes, bone.GetInfluences(), true, false, true );
            if( addTags )
                AddTagNodes( node.Nodes, bone.GetTags(), true, false );
            if( addParent && node.Parent != null )
                AddBoneNode( node.Nodes, bone.Parent, addInfs, addTags, true, false, expand );
            if( addChildren )
                AddBoneNodes( node.Nodes, bone.GetChildren(), addInfs, addTags, false, true );

            if( expand )
                node.Expand();
        }