123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) {
- return model.load( module, {
-
-
- initialize: function() {
- this.nodes = {};
- },
- creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
- childSource, childType, childIndex, childName, callback ) {
- var protos = getPrototypes( this.kernel, childExtendsID );
- if ( isHeightmap( protos ) ) {
-
- var node = this.nodes[ childID ];
-
- if ( this.nodes[ childID ] === undefined ){
-
- callback( false );
-
- var heightmapImage = new Image();
-
- heightmapImage.src = utility.resolveURI( childSource );
- var driver = this;
- heightmapImage.onload = function() {
-
-
- var canvas = document.createElement( "canvas" );
- canvas.setAttribute( "width", heightmapImage.width );
- canvas.setAttribute( "height", heightmapImage.height );
-
- var context = canvas.getContext( "2d" );
- context.drawImage( heightmapImage, 0, 0 );
- var heightmap = context.getImageData( 0, 0, heightmapImage.width,
- heightmapImage.height );
-
- driver.nodes[ childID ] = {
- heightmap: heightmap.data,
- width: heightmapImage.width,
- height: heightmapImage.height,
- }
-
- callback( true );
- }
- }
- }
-
- },
- gettingProperty: function( nodeID, propertyName, propertyValue ) {
-
-
- var node = this.nodes[ nodeID ];
-
-
- if ( !node ) {
- return;
- }
- switch ( propertyName ) {
- case "heightmap":
- return node.heightmap;
- case "heightmapWidth":
- return node.width;
- case "heightmapHeight":
- return node.height;
- }
- }
- } );
- function getPrototypes( kernel, extendsID ) {
- var prototypes = [];
- var id = extendsID;
- while ( id !== undefined ) {
- prototypes.push( id );
- id = kernel.prototype( id );
- }
-
- return prototypes;
- }
- function isHeightmap( prototypes ) {
- var found = false;
- if ( prototypes ) {
- for ( var i = 0; i < prototypes.length && !found; i++ ) {
- found = ( prototypes[ i ] === "http://vwf.example.com/heightmap.vwf" );
- }
- }
- return found;
- }
- } );
|