浏览代码

Added support for non square textures for sprites

David Catuhe 9 年之前
父节点
当前提交
d5ffd4b348

文件差异内容过多而无法显示
+ 4 - 4
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 4493 - 4492
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 3 - 3
dist/preview release/babylon.js


+ 16 - 5
dist/preview release/babylon.max.js

@@ -24958,8 +24958,12 @@ var BABYLON;
                     "logarithmicDepthConstant"
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
-                BABYLON.ColorCurves.PrepareUniforms(uniforms);
-                BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                if (this._defines.CAMERACOLORCURVES) {
+                    BABYLON.ColorCurves.PrepareUniforms(uniforms);
+                }
+                if (this._defines.CAMERACOLORGRADING) {
+                    BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                }
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights - 1 });
             }
@@ -26169,7 +26173,6 @@ var BABYLON;
         function SpriteManager(name, imgUrl, capacity, cellSize, scene, epsilon, samplingMode) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             this.name = name;
-            this.cellSize = cellSize;
             this.sprites = new Array();
             this.renderingGroupId = 0;
             this.layerMask = 0x0FFFFFFF;
@@ -26186,6 +26189,14 @@ var BABYLON;
             this._spriteTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._spriteTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
+            if (cellSize.width) {
+                this.cellWidth = cellSize.width;
+                this.cellHeight = cellSize.height;
+            }
+            else {
+                this.cellWidth = cellSize;
+                this.cellHeight = cellSize;
+            }
             this._scene = scene;
             this._scene.spriteManagers.push(this);
             var indices = [];
@@ -26318,7 +26329,7 @@ var BABYLON;
             // Sprites
             var deltaTime = engine.getDeltaTime();
             var max = Math.min(this._capacity, this.sprites.length);
-            var rowSize = baseSize.width / this.cellSize;
+            var rowSize = baseSize.width / this.cellWidth;
             var offset = 0;
             for (var index = 0; index < max; index++) {
                 var sprite = this.sprites[index];
@@ -26342,7 +26353,7 @@ var BABYLON;
             effect.setTexture("diffuseSampler", this._spriteTexture);
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
-            effect.setFloat2("textureInfos", this.cellSize / baseSize.width, this.cellSize / baseSize.height);
+            effect.setFloat2("textureInfos", this.cellWidth / baseSize.width, this.cellHeight / baseSize.height);
             // Fog
             if (this._scene.fogEnabled && this._scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
                 effect.setFloat4("vFogInfos", this._scene.fogMode, this._scene.fogStart, this._scene.fogEnd, this._scene.fogDensity);

文件差异内容过多而无法显示
+ 19 - 19
dist/preview release/babylon.noworker.js


+ 1 - 0
dist/preview release/what's new.md

@@ -3,6 +3,7 @@
 ### Major updates
     
 ### Updates
+- Added support for non square textures for sprites ([deltakosh](https://github.com/deltakosh)) 
 - Added support for texture arrays ([deltakosh](https://github.com/deltakosh)) 
 - Added `camera.isInFrustum` and `camera.isCompletelyInFrustum`. Can be used with meshes, submeshes and boundingInfo ([deltakosh](https://github.com/deltakosh)) 
 - Several memory allocation reduction ([benaadams](https://github.com/benaadams))

+ 6 - 2
src/Materials/babylon.standardMaterial.js

@@ -512,8 +512,12 @@ var BABYLON;
                     "logarithmicDepthConstant"
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
-                BABYLON.ColorCurves.PrepareUniforms(uniforms);
-                BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                if (this._defines.CAMERACOLORCURVES) {
+                    BABYLON.ColorCurves.PrepareUniforms(uniforms);
+                }
+                if (this._defines.CAMERACOLORGRADING) {
+                    BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                }
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights - 1 });
             }

+ 6 - 2
src/Materials/babylon.standardMaterial.ts

@@ -672,8 +672,12 @@
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
 
-                ColorCurves.PrepareUniforms(uniforms); 
-                ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers); 
+                if (this._defines.CAMERACOLORCURVES) {
+                    ColorCurves.PrepareUniforms(uniforms);
+                }
+                if (this._defines.CAMERACOLORGRADING) {
+                    ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                }
                 MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
 
                 this._effect = scene.getEngine().createEffect(shaderName,

+ 10 - 3
src/Sprites/babylon.spriteManager.js

@@ -4,7 +4,6 @@ var BABYLON;
         function SpriteManager(name, imgUrl, capacity, cellSize, scene, epsilon, samplingMode) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             this.name = name;
-            this.cellSize = cellSize;
             this.sprites = new Array();
             this.renderingGroupId = 0;
             this.layerMask = 0x0FFFFFFF;
@@ -21,6 +20,14 @@ var BABYLON;
             this._spriteTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._spriteTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
+            if (cellSize.width) {
+                this.cellWidth = cellSize.width;
+                this.cellHeight = cellSize.height;
+            }
+            else {
+                this.cellWidth = cellSize;
+                this.cellHeight = cellSize;
+            }
             this._scene = scene;
             this._scene.spriteManagers.push(this);
             var indices = [];
@@ -153,7 +160,7 @@ var BABYLON;
             // Sprites
             var deltaTime = engine.getDeltaTime();
             var max = Math.min(this._capacity, this.sprites.length);
-            var rowSize = baseSize.width / this.cellSize;
+            var rowSize = baseSize.width / this.cellWidth;
             var offset = 0;
             for (var index = 0; index < max; index++) {
                 var sprite = this.sprites[index];
@@ -177,7 +184,7 @@ var BABYLON;
             effect.setTexture("diffuseSampler", this._spriteTexture);
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
-            effect.setFloat2("textureInfos", this.cellSize / baseSize.width, this.cellSize / baseSize.height);
+            effect.setFloat2("textureInfos", this.cellWidth / baseSize.width, this.cellHeight / baseSize.height);
             // Fog
             if (this._scene.fogEnabled && this._scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
                 effect.setFloat4("vFogInfos", this._scene.fogMode, this._scene.fogStart, this._scene.fogEnd, this._scene.fogDensity);

+ 14 - 4
src/Sprites/babylon.spriteManager.ts

@@ -5,6 +5,8 @@
         public layerMask: number = 0x0FFFFFFF;
         public fogEnabled = true;
         public isPickable = false;
+        public cellWidth: number;
+        public cellHeight: number;
 
         /**
         * An event triggered when the manager is disposed.
@@ -41,7 +43,7 @@
             this._spriteTexture = value;
         }
 
-        constructor(public name: string, imgUrl: string, capacity: number, public cellSize: number, scene: Scene, epsilon?: number, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        constructor(public name: string, imgUrl: string, capacity: number, cellSize: any, scene: Scene, epsilon?: number, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
             this._capacity = capacity;
             this._spriteTexture = new Texture(imgUrl, scene, true, false, samplingMode);
             this._spriteTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
@@ -49,6 +51,14 @@
 
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
 
+            if (cellSize.width) {
+                this.cellWidth = cellSize.width;
+                this.cellHeight = cellSize.height;
+            } else {
+                this.cellWidth = cellSize;
+                this.cellHeight = cellSize;
+            }
+
             this._scene = scene;
             this._scene.spriteManagers.push(this);
 
@@ -173,7 +183,7 @@
 
                 result.hit = true;
                 result.pickedSprite = currentSprite;
-                result.distance = distance
+                result.distance = distance;
 
                 return result;
             }
@@ -192,7 +202,7 @@
             // Sprites
             var deltaTime = engine.getDeltaTime();
             var max = Math.min(this._capacity, this.sprites.length);
-            var rowSize = baseSize.width / this.cellSize;
+            var rowSize = baseSize.width / this.cellWidth;
 
             var offset = 0;
             for (var index = 0; index < max; index++) {
@@ -224,7 +234,7 @@
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
 
-            effect.setFloat2("textureInfos", this.cellSize / baseSize.width, this.cellSize / baseSize.height);
+            effect.setFloat2("textureInfos", this.cellWidth / baseSize.width, this.cellHeight / baseSize.height);
 
             // Fog
             if (this._scene.fogEnabled && this._scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {