Browse Source

Add per-image cache controls

pull/117/head
Adam Johnson 6 years ago
parent
commit
62f8b59ce2
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 29
      korman/exporter/image.py
  2. 2
      korman/properties/__init__.py
  3. 26
      korman/properties/prop_image.py
  4. 1
      korman/ui/__init__.py
  5. 25
      korman/ui/ui_image.py

29
korman/exporter/image.py

@ -67,17 +67,26 @@ class ImageCache:
self._read_stream = hsFileStream()
self._stream_handles = 0
def add_texture(self, key, num_levels, export_size, compression, data):
if key.ephemeral or self._exporter().texcache_method == "skip":
def add_texture(self, texture, num_levels, export_size, compression, data):
image = texture.image
image_name = str(texture)
key = (image_name, compression)
ex_method, im_method = self._exporter().texcache_method, image.plasma_image.texcache_method
method = set((ex_method, im_method))
if texture.ephemeral or "skip" in method:
self._images.pop(key, None)
return
elif im_method == "rebuild":
image.plasma_image.texcache_method = "use"
image = _CachedImage()
image.name = str(key)
image.name = image_name
image.mip_levels = num_levels
image.compression = compression
image.source_size = key.image.size
image.source_size = texture.image.size
image.export_size = export_size
image.image_data = data
self._images[(image.name, compression)] = image
self._images[key] = image
def _compact(self):
for key, image in self._images.copy().items():
@ -98,7 +107,14 @@ class ImageCache:
self._read_stream.close()
def get_from_texture(self, texture, compression):
if self._exporter().texcache_method != "use" or texture.ephemeral:
bl_image = texture.image
# If the texture is ephemeral (eg a lightmap) or has been marked "rebuild" or "skip"
# in the UI, we don't want anything from the cache. In the first two cases, we never
# want to cache that crap. In the latter case, we just want to signal a recache is needed.
ex_method, im_method = self._exporter().texcache_method, texture.image.plasma_image.texcache_method
method = set((ex_method, im_method))
if method != {"use"} or texture.ephemeral:
return None
key = (str(texture), compression)
@ -108,7 +124,6 @@ class ImageCache:
# ensure the texture key generally matches up with our copy of this image.
# if not, a recache will likely be triggered implicitly.
bl_image = texture.image
if tuple(bl_image.size) != cached_image.source_size:
return None

2
korman/properties/__init__.py

@ -16,6 +16,7 @@
import bpy
from .prop_camera import *
from .prop_image import *
from .prop_lamp import *
from . import modifiers
from .prop_object import *
@ -25,6 +26,7 @@ from .prop_world import *
def register():
bpy.types.Camera.plasma_camera = bpy.props.PointerProperty(type=PlasmaCamera)
bpy.types.Image.plasma_image = bpy.props.PointerProperty(type=PlasmaImage)
bpy.types.Lamp.plasma_lamp = bpy.props.PointerProperty(type=PlasmaLamp)
bpy.types.Object.plasma_net = bpy.props.PointerProperty(type=PlasmaNet)
bpy.types.Object.plasma_object = bpy.props.PointerProperty(type=PlasmaObject)

26
korman/properties/prop_image.py

@ -0,0 +1,26 @@
# This file is part of Korman.
#
# Korman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Korman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.props import *
class PlasmaImage(bpy.types.PropertyGroup):
texcache_method = EnumProperty(name="Texture Cache",
description="Texture Cache Settings",
items=[("skip", "Don't Cache Image", "This image is never cached."),
("use", "Use Image Cache", "This image should be cached."),
("rebuild", "Refresh Image Cache", "Forces this image to be recached on the next export.")],
default="use",
options=set())

1
korman/ui/__init__.py

@ -14,6 +14,7 @@
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
from .ui_camera import *
from .ui_image import *
from .ui_lamp import *
from .ui_list import *
from .ui_menus import *

25
korman/ui/ui_image.py

@ -0,0 +1,25 @@
# This file is part of Korman.
#
# Korman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Korman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy
class PlasmaImageEditorHeader(bpy.types.Header):
bl_space_type = "IMAGE_EDITOR"
def draw(self, context):
layout, image = self.layout, context.space_data.image
settings = image.plasma_image
layout.prop(settings, "texcache_method", text="")
Loading…
Cancel
Save