[WIP] Fix rendering for PanelSprite and Sprite instances with custom size and smoothing

This commit is contained in:
Florian Rival
2017-03-19 19:01:01 +01:00
parent 907f319ce7
commit 8f109d5a27
4 changed files with 30 additions and 26 deletions

View File

@@ -87,7 +87,6 @@ export default class InstancesEditorContainer extends Component {
}); });
this._mountEditorComponents(this.props); this._mountEditorComponents(this.props);
ResourcesLoader.loadTextures(this.props.project, () => {}, () => {});
this.renderScene(); this.renderScene();
} }

View File

@@ -62,7 +62,7 @@ RenderedPanelSpriteInstance.prototype.update = function() {
this._width = this._instance.getCustomWidth(); this._width = this._instance.getCustomWidth();
this._height = this._instance.getCustomHeight(); this._height = this._instance.getCustomHeight();
} else { } else {
var tiledSprite = gd.asTiledSpriteObject(this._associatedObject); var tiledSprite = gd.asPanelSpriteObject(this._associatedObject);
this._width = tiledSprite.getWidth(); this._width = tiledSprite.getWidth();
this._height = tiledSprite.getHeight(); this._height = tiledSprite.getHeight();
} }

View File

@@ -85,6 +85,9 @@ RenderedSpriteInstance.prototype.updatePIXISprite = function() {
this._pixiObject.texture.frame.width; this._pixiObject.texture.frame.width;
this._pixiObject.scale.y = this._instance.getCustomHeight() / this._pixiObject.scale.y = this._instance.getCustomHeight() /
this._pixiObject.texture.frame.height; this._pixiObject.texture.frame.height;
} else {
this._pixiObject.scale.x = 1;
this._pixiObject.scale.y = 1;
} }
this._pixiObject.position.x = this._instance.getX() + this._pixiObject.position.x = this._instance.getX() +
(this._centerX - this._originX) * Math.abs(this._pixiObject.scale.x); (this._centerX - this._originX) * Math.abs(this._pixiObject.scale.x);

View File

@@ -61,6 +61,15 @@ export default class ResourceLoader {
return this._cache.cacheSystemFilename(project, filename, filename); return this._cache.cacheSystemFilename(project, filename, filename);
} }
static _initializeTexture(resource, texture) {
if (resource.getKind() !== 'image') return;
const imageResource = gd.asImageResource(resource);
if (!imageResource.isSmooth()) {
texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;
}
}
static loadTextures(project, onProgress, onComplete) { static loadTextures(project, onProgress, onComplete) {
const resourcesManager = project.getResourcesManager(); const resourcesManager = project.getResourcesManager();
const loader = PIXI.loader; const loader = PIXI.loader;
@@ -89,15 +98,10 @@ export default class ResourceLoader {
for (const resourceName in loadedResources) { for (const resourceName in loadedResources) {
if (loadedResources.hasOwnProperty(resourceName)) { if (loadedResources.hasOwnProperty(resourceName)) {
const resource = resourcesManager.getResource(resourceName); const resource = resourcesManager.getResource(resourceName);
if (resource.getKind() !== 'image') return; if (resource.getKind() !== 'image') continue;
const imageResource = gd.asImageResource(resource);
loadedTextures[resourceName] = loadedResources[resourceName].texture; loadedTextures[resourceName] = loadedResources[resourceName].texture;
if (!imageResource.isSmooth()) { ResourceLoader._initializeTexture(resource, loadedTextures[resourceName]);
loadedTextures[
resourceName
].baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;
}
} }
} }
@@ -117,7 +121,10 @@ export default class ResourceLoader {
.getResourcesManager() .getResourcesManager()
.getResource(resourceName) .getResource(resourceName)
.getFile(); .getFile();
return ResourceLoader._getSystemFullFilename(project, resourceRelativePath) return ResourceLoader._getSystemFullFilename(
project,
resourceRelativePath
);
} }
return resourceName; return resourceName;
@@ -128,24 +135,19 @@ export default class ResourceLoader {
return loadedTextures[resourceName]; return loadedTextures[resourceName];
} }
console.warn( if (!project.getResourcesManager().hasResource(resourceName))
"Trying to get a texture that wasn't preloaded: ", return invalidTexture;
resourceName
const resource = project.getResourcesManager().getResource(resourceName);
if (resource.getKind() !== 'image') return invalidTexture;
const resourceRelativePath = resource.getFile();
loadedTextures[resourceName] = PIXI.Texture.fromImage(
ResourceLoader._getSystemFullFilename(project, resourceRelativePath)
); );
if (project.getResourcesManager().hasResource(resourceName)) { ResourceLoader._initializeTexture(resource, loadedTextures[resourceName]);
const resourceRelativePath = project return loadedTextures[resourceName];
.getResourcesManager()
.getResource(resourceName)
.getFile();
loadedTextures[resourceName] = PIXI.Texture.fromImage(
ResourceLoader._getSystemFullFilename(project, resourceRelativePath)
);
//TODO: smooth handling
return loadedTextures[resourceName];
}
return invalidTexture;
} }
static getFontFamily(project, fontFilename) { static getFontFamily(project, fontFilename) {