Created
          December 8, 2011 20:26 
        
      - 
      
- 
        Save nat-n/1448410 to your computer and use it in GitHub Desktop. 
    A JaxGL Model file which uses AsyncHelper.js.coffee (gist: 1448794) to load and display a model from ajax and/or indexedDB
  
        
  
    
      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
    
  
  
    
  | Jax.getGlobal()['LoadedMesh'] = Jax.Model.create | |
| after_initialize: -> | |
| model_data = null | |
| @mesh = new Jax.Mesh | |
| init: (vertices, colors, texCoords, normals, indices) -> | |
| if model_data | |
| vertices.push datum for datum in model_data["vertices"][0]["values"] | |
| normals.push datum for datum in model_data["vertices"][1]["values"] | |
| indices.push datum for datum in model_data["connectivity"][0]["indices"] | |
| update: ((updated_mesh) => model_data = updated_mesh; @mesh.rebuild()) | |
| if @indexedDB and @objectStore and @key | |
| this.load_from_idb @indexedDB, @objectStore, @key, | |
| ((data) => | |
| @mesh.update data | |
| console.log "loaded from indexedDB"), | |
| ((e) => | |
| if @json_path | |
| this.load_json @json_path, ((data) => | |
| @mesh.update data | |
| this.save_to_idb idb, @idb_version, @objectStore, @key, data) | |
| else console.log "No accessible data source") | |
| else | |
| if @json_path | |
| this.load_json @json_path, @mesh.update | |
| else console.log "No accessible data source" | |
| helpers: -> [ AsyncHelper ] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment