コード例 #1
0
        public virtual void ReadController( XmlNode node, ColladaMeshInfo meshInfo )
        {
            // Set up the current geometry name
            string controllerName = node.Attributes[ "id" ].Value;
            string target = node.Attributes[ "target" ].Value;

            SkinController controller = new SkinController( controllerName );
            controller.Target = meshInfo.Geometries[ target ];

            meshInfo.Controllers[ controllerName ] = controller;

            foreach( XmlNode childNode in node.ChildNodes )
            {
                switch( childNode.Name )
                {
                case "skin":
                    ReadSkin( controller, childNode, meshInfo );
                    break;
                default:
                    DebugMessage( childNode );
                    break;
                }
            }
        }
コード例 #2
0
        public void ReadJoints( SkinController controller,
                               XmlNode node, ColladaMeshInfo meshInfo )
        {
            Dictionary<int, List<InputSourceCollection>> inputSources =
                new Dictionary<int, List<InputSourceCollection>>();
            foreach( XmlNode childNode in node.ChildNodes )
            {
                switch( childNode.Name )
                {
                case "input":
                    ReadInput( inputSources, null, childNode, meshInfo );
                    break;
                default:
                    break;
                }
            }
            // process joints here
            InputSource jointInput = null;
            InputSource invBindMatrixInput = null;
            foreach( List<InputSourceCollection> inputs in inputSources.Values )
            {
                foreach( InputSourceCollection tmp in inputs )
                {
                    Debug.Assert( tmp.GetSources().Count == 1 );
                    InputSource source = tmp.GetSources()[ 0 ];
                    switch( source.Semantic )
                    {
                    case "JOINT":
                        jointInput = source;
                        break;
                    case "INV_BIND_MATRIX":
                        invBindMatrixInput = source;
                        break;
                    default:
                        log.InfoFormat( "Unhandled joint input semantic: {0}", source.Semantic );
                        break;
                    }
                }
            }
            Debug.Assert( jointInput != null && invBindMatrixInput != null );
            string jointParam = "";
            if( jointInput.Accessor.ContainsParam( "JOINT" ) )
                jointParam = "JOINT";
            string invBindParam = "";
            if( invBindMatrixInput.Accessor.ContainsParam( "INV_BIND_MATRIX" ) )
                invBindParam = "INV_BIND_MATRIX";
            else if( invBindMatrixInput.Accessor.ContainsParam( "TRANSFORM" ) )
                invBindParam = "TRANSFORM";
            for( int ptIndex = 0; ptIndex < jointInput.Count; ++ptIndex )
            {
                string jointName = (String) jointInput.Accessor.GetParam( jointParam, ptIndex );
                Matrix4 invBindMatrix = (Matrix4) invBindMatrixInput.Accessor.GetParam( invBindParam, ptIndex );
                if( controller.InverseBindMatrices.ContainsKey( jointName ) )
                {
                    string msg =
                        string.Format( "Duplicate inverse bind matrix found in controller '{0}' for joint '{1}'; Aborting export.",
                                      controller.Name, jointName );

                    log.Error( msg );
                    throw new Exception( msg );
                }
                // Debug.Assert(controller.InvBindTransforms[jointName] == invBindMatrix);
                controller.InverseBindMatrices[ jointName ] = invBindMatrix;
            }
        }
コード例 #3
0
 public void ReadSkinVerticesInput( SkinController controller,
                                   XmlNode node, ColladaMeshInfo meshInfo )
 {
     string semantic = node.Attributes[ "semantic" ].Value;
     switch( semantic )
     {
     case "BIND_SHAPE_POSITION":
     case "BIND_SHAPE_NORMAL":
         ReadInput( controller.InputSources, null, node, meshInfo );
         return;
     case "JOINTS_AND_WEIGHTS":
         {
             string source = node.Attributes[ "source" ].Value;
             // string off leading '#'
             source = source.Substring( 1 );
             controller.Target.Combiner = Combiners[ source ];
         }
         break;
     default:
         log.InfoFormat( "Not currently handling semantic {0} for skin vertices input", semantic );
         break;
     }
 }
コード例 #4
0
 public void ReadSkinVertices( SkinController controller,
                              XmlNode node, ColladaMeshInfo meshInfo )
 {
     foreach( XmlNode childNode in node.ChildNodes )
     {
         switch( childNode.Name )
         {
         case "input":
             ReadSkinVerticesInput( controller, childNode, meshInfo );
             break;
         default:
             DebugMessage( childNode );
             break;
         }
     }
 }
コード例 #5
0
 public virtual void ReadSkin( SkinController controller, XmlNode node, ColladaMeshInfo meshInfo )
 {
     foreach( XmlNode childNode in node.ChildNodes )
     {
         switch( childNode.Name )
         {
         case "source":
             ReadSource( controller, childNode, meshInfo );
             break;
         case "vertices":
             ReadSkinVertices( controller, childNode, meshInfo );
             break;
         default:
             DebugMessage( childNode );
             break;
         }
     }
 }
コード例 #6
0
        public override void ReadSkin( SkinController controller, XmlNode node, ColladaMeshInfo meshInfo )
        {
            string skinSource = node.Attributes[ "source" ].Value;
            if( skinSource.StartsWith( "#" ) )
                // strip off the leading '#'
                skinSource = skinSource.Substring( 1 );
            else
                log.InfoFormat( "Skin source {0} does not start with '#'", skinSource );

            if( controller.Target != null )
            {
                string msg = string.Format( "Duplicate skin for controller: {0}", controller.Name );
                throw new Exception( msg );
            }

            // The skin source may actually be a morph controller.
            if( meshInfo.Controllers.ContainsKey( skinSource ) )
            {
                controller.Target = meshInfo.Controllers[ skinSource ].Target;
                controller.Morph = meshInfo.Controllers[ skinSource ] as MorphController;
            }
            else if( meshInfo.Geometries.ContainsKey( skinSource ) )
            {
                controller.Target = meshInfo.Geometries[ skinSource ];
            }

            foreach( XmlNode childNode in node.ChildNodes )
            {
                switch( childNode.Name )
                {
                case "source":
                    ReadSource( controller, childNode, meshInfo );
                    break;
                case "joints":
                    ReadJoints( controller, childNode, meshInfo );
                    break;
                case "vertex_weights":
                    controller.Target.Combiner =
                        ReadVertexWeights( childNode, meshInfo );
                    break;
                case "bind_shape_matrix":
                    {
                        Matrix4 bindShapeMatrix = Matrix4.Identity;
                        ReadMatrix( ref bindShapeMatrix, childNode );
                        controller.BindShapeMatrix = bindShapeMatrix;
                    }
                    break;
                case "extra":
                default:
                    DebugMessage( childNode );
                    break;
                }
            }
        }
コード例 #7
0
        // In Collada 1.4, skins have targets (source attribute), but
        // controllers do not
        public override void ReadController( XmlNode node, ColladaMeshInfo meshInfo )
        {
            // Set up the current geometry name
            string controllerName = node.Attributes[ "id" ].Value;
            // string target = node.Attributes["target"].Value;

            foreach( XmlNode childNode in node.ChildNodes )
            {
                switch( childNode.Name )
                {
                case "skin":
                    SkinController skinController = new SkinController( controllerName );
                    // skinController.Target = meshInfo.geometries[target];
                    meshInfo.Controllers[ controllerName ] = skinController;
                    ReadSkin( skinController, childNode, meshInfo );
                    break;

                case "morph":
                    string method = "NORMALIZED";
                    if( childNode.Attributes[ "method" ] != null )
                        method = childNode.Attributes[ "method" ].Value;
                    MorphController morphController = new MorphController( controllerName, method );
                    // morphController.Target = meshInfo.geometries[target];
                    meshInfo.Controllers[ controllerName ] = morphController;
                    ReadMorph( morphController, childNode, meshInfo );
                    break;

                default:
                    DebugMessage( childNode );
                    break;
                }
            }
        }