- 
                Notifications
    You must be signed in to change notification settings 
- Fork 7
Fix transformations not applied #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            aronfiechter
  wants to merge
  8
  commits into
  wanadev:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
hegias:fix-transformations-not-applied
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      56f2000
              
                Add Three.js dependency to use Matrix4 math for affine transformations
              
              
                 bb1499a
              
                Add module to compute TRS affine transformation matrix of a node
              
              
                 de4f5ec
              
                Use trsMatrix as default case when getting child matrix
              
              
                 b2981ea
              
                Update dist
              
              
                 bb77739
              
                Change to returning column-major from TRS
              
              
                 8a5a336
              
                Update dist files
              
              
                 978909a
              
                Add tests for scenes with scaling and rotation
              
              
                 a853fd5
              
                Add test for scenes with translations and scaling
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { Matrix4, Quaternion } from 'three'; | ||
|  | ||
| const trsMatrix = { | ||
|  | ||
| /** | ||
| * Get the composed TRS (trasnlation, rotation, scale) affine transformation matrix for a given node. | ||
| * | ||
| * @param {Object} node a node in a GLTF | ||
| * @param {Array<number>} [node.translation] array of 3 values for a translation | ||
| * @param {Array<number>} [node.rotation] an array of four values for a rotation (quaternion) | ||
| * @param {Array<number>} [node.scale] an array of three values for a scale | ||
| */ | ||
| getTRSMatrix({ translation, rotation, scale }) { | ||
| const t = translation ? trsMatrix._affineT(translation) : trsMatrix._I(); | ||
| const r = rotation ? trsMatrix._affineR(rotation) : trsMatrix._I(); | ||
| const s = scale ? trsMatrix._affineS(scale) : trsMatrix._I(); | ||
|  | ||
| // Post-multiply: T * R * S | ||
| const TRS = t.multiply(r).multiply(s); | ||
|  | ||
| // toArray returns a column-major, and we need exactly that one | ||
| return TRS.toArray(); | ||
| }, | ||
|  | ||
| /** | ||
| * Three functions that use `_affine`, to simplify calls above. | ||
| */ | ||
| _affineT(t) { | ||
| return trsMatrix._affine({ t }); | ||
| }, | ||
| _affineR(r) { | ||
| return trsMatrix._affine({ r }); | ||
| }, | ||
| _affineS(s) { | ||
| return trsMatrix._affine({ s }); | ||
| }, | ||
|  | ||
| /** | ||
| * Identity 4x4 matrix. | ||
| */ | ||
| _I() { | ||
| return new Matrix4().identity(); | ||
| }, | ||
|  | ||
| /** | ||
| * Convert one of the t, r, or s arrays into a 4x4 affine transformation matrix. | ||
| * The passed parameter object p should contain only one of the fields t, r, or s. | ||
| * | ||
| * @param {Object} p | ||
| * @param {Array<number>} [p.t] an array of three values for a transaltion | ||
| * @param {Array<number>} [p.r] an array of four values for a rotation (quaternion) | ||
| * @param {Array<number>} [p.s] an array of three values for a scale | ||
| */ | ||
| _affine({ t, r, s }) { | ||
| if (t) { | ||
| return new Matrix4().makeTranslation(t[0], t[1], t[2]); | ||
| } | ||
| if (r) { | ||
| return new Matrix4().makeRotationFromQuaternion(new Quaternion(r[0], r[1], r[2], r[3])); | ||
| } | ||
| if (s) { | ||
| return new Matrix4().makeScale(s[0], s[1], s[2]); | ||
| } | ||
| }, | ||
| }; | ||
|  | ||
| export default trsMatrix; | 
            Binary file not shown.
          
    
            Binary file not shown.
          
    
            Binary file not shown.
          
    
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late answer !
We don't want to depend on a specific engine like Three, especially as we usually work with Babylonjs. I saw that three was used only in
trs-matrix.jsto break down matrices. Is it possible to implement functions like multiply, or quaternions in the lib?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see three options:
Personally I would prefer the second option, but I haven't been able to find a library like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know https://github.com/toji/gl-matrix develop by Tojiro (but I nevers used it), well know and tested library, feel free to take a look !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw you were using it and it seemed ok, but the API looked a bit weird to me.
I'll try converting to using that when I have some time.