Difference between revisions of "User:Dsventura"
(added second 0.2 bug) |
(added project explaination to wiki (saving paper ftw)) |
||
Line 39: | Line 39: | ||
[https://github.com/DanVentura/popcorn-js/tree/t331/plugins/facebook Source] | [https://github.com/DanVentura/popcorn-js/tree/t331/plugins/facebook Source] | ||
+ | |||
+ | <h1>GAM670 - XAnimation</h1> | ||
+ | <h2>Overview</h2> | ||
+ | Animation in DirectX9 can be done using .X files. The .X extension refers to a file containing a Microsoft proprietary format for exported 3D models. This format is similar to COLLADA, except the file parsing is handled by DirectX internally. To export a model in .X format in 3Ds MAX, I used a plugin from PandaSoft called the Panda DirectX Max exporter (link on last page). | ||
+ | |||
+ | |||
+ | Once exported, the file contains information each object and maintains their hierarchical relationships between each object. Each object has a frame container and a mesh container. The frame contains information for positioning, while the mesh contains mesh related information such as: bones, textures, etc. To perform skeletal information, the frames must be arranged in an inheritance hierarchy so that the frame's matrix transformations would be relative to it's parent, respectively (Figure 1). | ||
+ | |||
+ | [[Image:FrameMeshHierarchyExample.png]] | ||
+ | |||
+ | (*Source - http://www.toymaker.info/Games/html/load_x_hierarchy.html) | ||
+ | |||
+ | Figure 1: Inheritance hierarchy consisting of a body and two arms. (“Left Arm Frame” would be a shoulder or joint. The name in this diagram may be misleading) | ||
+ | |||
+ | This hierarchy would be established in 3Ds MAX through linking. For more information on how to use bones and make skeletal animations in 3Ds MAX, refer to the references. | ||
+ | |||
+ | In order to properly load this information, we first need to do a little inheritance of some structs to make our lives easier (refer to MeshStructs.h). We need to extend D3DXMESHCONTAINER and D3DXFRAME with some extra data so we can support skinning. Basically, skinning is a technique where you combine the frame (bone) and mesh (skin) matrices so that the mesh's vertex positions will be altered depending on the frame's movement; making the mesh stretch and contract like actual skin. For more information on skinning, refer to the “X File Hierarchy Loading” link in references. | ||
+ | |||
+ | |||
+ | Once we have extended the structures, we have to implement the ID3DXAllocateHierarchy interface to support the extra information we've put into these structures and load the file properly. These functions are called internally as the D3DXloadMeshHierarchyFromX function parses the .X file. (refer to MeshHierarchy.h) | ||
+ | |||
+ | |||
+ | To put all of this into the framework, we create an XObject class which is derived from Object. This will hold model information as well as the animation controller. It will also hold information that allows us to change animation sets and the speed of the animation. (refer to XObject.h) | ||
+ | |||
+ | <h4>Animation Controller</h4> | ||
+ | To give you an overview of the animation controller and it's functions, here's a list of functions used in this example (descriptions from msdn.microsoft.com): | ||
+ | |||
+ | |||
+ | '''LPD3DXANIMATIONCONTROLLER m_animController;''' | ||
+ | |||
+ | ''// Takes the filename and extracts the information from the x file. memoryAllocator is the'' | ||
+ | |||
+ | ''// frame hierarchy, frameRoot is the parent frame, and m_animController is the COM object'' | ||
+ | |||
+ | '''D3DXLoadMeshHierarchyFromX(filename, D3DXMESH_MANAGED, d3dd, &memoryAllocator, NULL, &m_frameRoot, &m_animController);''' | ||
+ | |||
+ | ''// Like any COM object, you must release it when you're done'' | ||
+ | |||
+ | '''m_animController->Release();''' | ||
+ | |||
+ | ''// Returns how many different animations are stored in the file'' | ||
+ | |||
+ | '''m_animController->GetMaxNumAnimationSets();''' | ||
+ | |||
+ | ''// Advances the animation timeline'' | ||
+ | |||
+ | '''m_animController->AdvanceTime(elapsedTime, NULL);''' | ||
+ | |||
+ | ''// Retieves an LPD3DXANIMATIONSET'' | ||
+ | |||
+ | '''m_animController->GetAnimationSet(m_currentAnimationSet, &set );''' | ||
+ | |||
+ | ''// This method sets the animation set to the specified track for mixing. The animation set for'' | ||
+ | |||
+ | ''// each track is blended according to the track weight and speed when AdvanceTime is called'' | ||
+ | |||
+ | '''m_animController->SetTrackAnimationSet( newTrack, set );''' | ||
+ | |||
+ | ''// Removes events from the animation track'' | ||
+ | |||
+ | '''m_animController->UnkeyAllTrackEvents( m_currentTrack );''' | ||
+ | |||
+ | ''// Enables or disables an animation track'' | ||
+ | |||
+ | '''m_animController->KeyTrackEnable( m_currentTrack, FALSE, startTime );''' | ||
+ | |||
+ | ''// Sets the rate of play of an animation track'' | ||
+ | |||
+ | '''m_animController->KeyTrackSpeed( m_currentTrack, newSpeed, m_currentTime, duration, D3DXTRANSITION_LINEAR );''' | ||
+ | |||
+ | ''// Changes the weight of an animation track. The weight is used as a multiplier when combining'' | ||
+ | |||
+ | ''// multiple tracks together'' | ||
+ | |||
+ | '''m_animController->KeyTrackWeight( m_currentTrack, newWeight, m_currentTime, duration, D3DXTRANSITION_LINEAR );''' | ||
+ | |||
+ | ''// Enables or disables a track in the animation controller'' | ||
+ | |||
+ | '''m_animController->SetTrackEnable( newTrack, TRUE );''' |
Revision as of 14:20, 30 March 2011
Contents
Information
Name: Dan Ventura
IRC name: danman
Email: dsventura@learn.senecac.on.ca
GAM670 Team: GAM670 Slap Your Grandma
Blog: dsventura.blogspot.com
GitHub Repository: DanVentura@github
OSD600
Firefox Build
Building Firefox 4 - Minefield
0.1
Processing.js
Popcorn.js
127-Make it easier to specify subtitles
Note: this bug is invalid, however I created subtitle unit tests in the process. (popcorn.subtitle.unit.js and popcorn.subtitle.unit.html)
305-Create Unit tests for subtitle plugin
0.2
Popcorn.js
GAM670 - XAnimation
Overview
Animation in DirectX9 can be done using .X files. The .X extension refers to a file containing a Microsoft proprietary format for exported 3D models. This format is similar to COLLADA, except the file parsing is handled by DirectX internally. To export a model in .X format in 3Ds MAX, I used a plugin from PandaSoft called the Panda DirectX Max exporter (link on last page).
Once exported, the file contains information each object and maintains their hierarchical relationships between each object. Each object has a frame container and a mesh container. The frame contains information for positioning, while the mesh contains mesh related information such as: bones, textures, etc. To perform skeletal information, the frames must be arranged in an inheritance hierarchy so that the frame's matrix transformations would be relative to it's parent, respectively (Figure 1).
(*Source - http://www.toymaker.info/Games/html/load_x_hierarchy.html)
Figure 1: Inheritance hierarchy consisting of a body and two arms. (“Left Arm Frame” would be a shoulder or joint. The name in this diagram may be misleading)
This hierarchy would be established in 3Ds MAX through linking. For more information on how to use bones and make skeletal animations in 3Ds MAX, refer to the references.
In order to properly load this information, we first need to do a little inheritance of some structs to make our lives easier (refer to MeshStructs.h). We need to extend D3DXMESHCONTAINER and D3DXFRAME with some extra data so we can support skinning. Basically, skinning is a technique where you combine the frame (bone) and mesh (skin) matrices so that the mesh's vertex positions will be altered depending on the frame's movement; making the mesh stretch and contract like actual skin. For more information on skinning, refer to the “X File Hierarchy Loading” link in references.
Once we have extended the structures, we have to implement the ID3DXAllocateHierarchy interface to support the extra information we've put into these structures and load the file properly. These functions are called internally as the D3DXloadMeshHierarchyFromX function parses the .X file. (refer to MeshHierarchy.h)
To put all of this into the framework, we create an XObject class which is derived from Object. This will hold model information as well as the animation controller. It will also hold information that allows us to change animation sets and the speed of the animation. (refer to XObject.h)
Animation Controller
To give you an overview of the animation controller and it's functions, here's a list of functions used in this example (descriptions from msdn.microsoft.com):
LPD3DXANIMATIONCONTROLLER m_animController;
// Takes the filename and extracts the information from the x file. memoryAllocator is the
// frame hierarchy, frameRoot is the parent frame, and m_animController is the COM object
D3DXLoadMeshHierarchyFromX(filename, D3DXMESH_MANAGED, d3dd, &memoryAllocator, NULL, &m_frameRoot, &m_animController);
// Like any COM object, you must release it when you're done
m_animController->Release();
// Returns how many different animations are stored in the file
m_animController->GetMaxNumAnimationSets();
// Advances the animation timeline
m_animController->AdvanceTime(elapsedTime, NULL);
// Retieves an LPD3DXANIMATIONSET
m_animController->GetAnimationSet(m_currentAnimationSet, &set );
// This method sets the animation set to the specified track for mixing. The animation set for
// each track is blended according to the track weight and speed when AdvanceTime is called
m_animController->SetTrackAnimationSet( newTrack, set );
// Removes events from the animation track
m_animController->UnkeyAllTrackEvents( m_currentTrack );
// Enables or disables an animation track
m_animController->KeyTrackEnable( m_currentTrack, FALSE, startTime );
// Sets the rate of play of an animation track
m_animController->KeyTrackSpeed( m_currentTrack, newSpeed, m_currentTime, duration, D3DXTRANSITION_LINEAR );
// Changes the weight of an animation track. The weight is used as a multiplier when combining
// multiple tracks together
m_animController->KeyTrackWeight( m_currentTrack, newWeight, m_currentTime, duration, D3DXTRANSITION_LINEAR );
// Enables or disables a track in the animation controller
m_animController->SetTrackEnable( newTrack, TRUE );