소스 검색

Simpler tool to bind an AdvancedDT to a mesh

David Catuhe 8 년 전
부모
커밋
6230ea2ba5

+ 2 - 1
dist/preview release/gui/babylon.gui.d.ts

@@ -7,7 +7,7 @@ declare module BABYLON.GUI {
         private _background;
         private _rootContainer;
         background: string;
-        constructor(name: string, size: number, scene: Scene);
+        constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
         removeControl(control: Control): AdvancedDynamicTexture;
@@ -15,6 +15,7 @@ declare module BABYLON.GUI {
         private _onResize();
         private _checkUpdate();
         private _render();
+        static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number): AdvancedDynamicTexture;
     }
 }
 

+ 20 - 4
dist/preview release/gui/babylon.gui.js

@@ -15,14 +15,18 @@ var BABYLON;
     (function (GUI) {
         var AdvancedDynamicTexture = (function (_super) {
             __extends(AdvancedDynamicTexture, _super);
-            function AdvancedDynamicTexture(name, size, scene) {
-                if (size === void 0) { size = 0; }
-                var _this = _super.call(this, name, size, scene, false, BABYLON.Texture.NEAREST_SAMPLINGMODE, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
+            function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
+                if (width === void 0) { width = 0; }
+                if (height === void 0) { height = 0; }
+                if (generateMipMaps === void 0) { generateMipMaps = false; }
+                if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
+                var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
                 _this._isDirty = false;
                 _this._rootContainer = new GUI.Container("root");
                 _this._renderObserver = _this.getScene().onBeforeRenderObservable.add(function () { return _this._checkUpdate(); });
                 _this._rootContainer._link(null, _this);
-                if (!size) {
+                _this.hasAlpha = true;
+                if (!width || !height) {
                     _this._resizeObserver = _this.getScene().getEngine().onResizeObservable.add(function () { return _this._onResize(); });
                     _this._onResize();
                 }
@@ -96,6 +100,18 @@ var BABYLON;
                 var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
                 this._rootContainer._draw(measure, context);
             };
+            // Statics
+            AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height) {
+                if (width === void 0) { width = 1024; }
+                if (height === void 0) { height = 1024; }
+                var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
+                var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
+                material.backFaceCulling = false;
+                material.emissiveTexture = result;
+                material.opacityTexture = result;
+                mesh.material = material;
+                return result;
+            };
             return AdvancedDynamicTexture;
         }(BABYLON.DynamicTexture));
         GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


+ 21 - 4
gui/src/advancedDynamicTexture.ts

@@ -20,15 +20,17 @@ module BABYLON.GUI {
             this._background = value;
             this.markAsDirty();
         }
-        
-        constructor(name: string, size = 0, scene: Scene) {
-            super(name, size, scene, false, Texture.NEAREST_SAMPLINGMODE, Engine.TEXTUREFORMAT_RGBA);
+       
+        constructor(name: string, width = 0, height = 0, scene: Scene, generateMipMaps = false, samplingMode = Texture.NEAREST_SAMPLINGMODE) {
+            super(name, {width: width, height: height}, scene, generateMipMaps, samplingMode, Engine.TEXTUREFORMAT_RGBA);
 
             this._renderObserver = this.getScene().onBeforeRenderObservable.add(() => this._checkUpdate());
 
             this._rootContainer._link(null, this);
 
-            if (!size) {
+            this.hasAlpha = true;
+
+            if (!width || !height) {
                 this._resizeObserver = this.getScene().getEngine().onResizeObservable.add(() => this._onResize());
                 this._onResize();
             }
@@ -101,5 +103,20 @@ module BABYLON.GUI {
             var measure = new Measure(0, 0, renderWidth, renderHeight);
             this._rootContainer._draw(measure, context);
         }
+
+        // Statics
+        public static CreateForMesh(mesh: AbstractMesh, width = 1024, height = 1024): AdvancedDynamicTexture {
+            var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, Texture.TRILINEAR_SAMPLINGMODE);
+
+            var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
+            material.backFaceCulling = false;
+            material.emissiveTexture = result;
+            material.opacityTexture = result;
+
+            mesh.material = material;
+
+            return result;
+        }
+
     }    
 }