Export ImageTexture node for an image identified in material node tree #39
@ -266,6 +266,18 @@ def export(file,
|
||||
|
||||
# store files to copy
|
||||
copy_set = set()
|
||||
# if path_mode is copy, create a temporary folder particular
|
||||
|
||||
# to this export operation, to stored image data to an image_file,
|
||||
# for those image in a packed set or otherwise not existing on disk
|
||||
if path_mode == 'COPY':
|
||||
blender_tempfolder = bpy.app.tempdir
|
||||
import uuid, os, os.path
|
||||
temporary_image_directory = os.path.join(blender_tempfolder,uuid.uuid4().hex)
|
||||
os.mkdir(temporary_image_directory)
|
||||
logger.info("temporary_image_directory: %s" % temporary_image_directory )
|
||||
else:
|
||||
temporary_image_directory = None
|
||||
|
||||
|
||||
# store names of newly created meshes, so we dont overlap
|
||||
mesh_name_set = set()
|
||||
@ -1201,7 +1213,7 @@ def export(file,
|
||||
image=imageTextureNode.image
|
||||
image_id = quoteattr(unique_name(image, IM_ + image.name, uuid_cache_image, clean_func=clean_def, sep="_"))
|
||||
logger.info("write ImageTexture X3D node for %r format %r filepath %r" % (image.name, image.file_format, image.filepath ))
|
||||
return
|
||||
|
||||
|
||||
|
||||
if image.tag:
|
||||
@ -1213,12 +1225,43 @@ def export(file,
|
||||
fw('%s<ImageTexture ' % ident)))
|
||||
fw('DEF=%s\n' % image_id)
|
||||
|
||||
# both branches of the following if-then block will
|
||||
# set a variable images to a sequence of strings, each string
|
||||
# a url to be entered into the MFString value of the
|
||||
# attribute url of the X3D ImageTexture element
|
||||
|
||||
if (not image_record.is_packed):
|
||||
# determine condition under which we want to directly write the the
|
||||
# image data to a temporary location for purposes of export. This will
|
||||
# only be done if the path_mode is COPY and either the filepath is empty
|
||||
# or the image has a packed file embedded in the .blend data
|
||||
|
||||
has_packed_file = image.packed_file and image.packed_file.size > 0
|
||||
|
||||
if has_packed_file or not imageTextureNode.image.filepath :
|
||||
# assume that if the data has a packed file or it
|
||||
# an empty file path then in the url field of the node
|
||||
Cedric Steiert
commented
comment is a bit tricky to read, maybe simplify: "Write only the filename if image is packed or has no filepath provided" comment is a bit tricky to read, maybe simplify: "Write only the filename if image is packed or has no filepath provided"
|
||||
# where just going to give a filename
|
||||
use_file_format = image.file_format or 'PNG'
|
||||
image_ext = {'JPEG':'.jpg' , 'PNG':'.png'}[use_file_format]
|
||||
image_base = os.path.splitext( os.path.basename(image.name))[0]
|
||||
image_filename = image_base + image_ext
|
||||
|
||||
|
||||
if temporary_image_directory:
|
||||
filepath_full = os.path.join(temporary_image_directory, image_filename)
|
||||
|
||||
logger.info("writing image for texture to %s" % filepath_full)
|
||||
image.save( filepath = filepath_full )
|
||||
|
||||
filepath_ref = bpy_extras.io_utils.path_reference(
|
||||
filepath_full,
|
||||
temporary_image_directory,
|
||||
base_dst,
|
||||
path_mode,
|
||||
"textures",
|
||||
copy_set,
|
||||
image.library)
|
||||
image_urls = [filepath_ref]
|
||||
else:
|
||||
image_urls = [image_filename]
|
||||
logger.warn("dangling image url %r" % [image_filename])
|
||||
else:
|
||||
Cedric Steiert
commented
warn is deprecated, use warning instead warn is deprecated, use warning instead
|
||||
# this is the legacy algorithm for determining
|
||||
# a set of urls based on value of image.filepath and the
|
||||
Cedric Steiert
commented
Could also get simplified: "Legacy Algorithm for preparing and normalizing image filepaths: Get the full path, reference path (e.g. relative), filename" Could also get simplified: "Legacy Algorithm for preparing and normalizing image filepaths: Get the full path, reference path (e.g. relative), filename"
|
||||
# argument path_mode passed in to the export function
|
||||
@ -1239,22 +1282,20 @@ def export(file,
|
||||
images.append(filepath_full)
|
||||
|
||||
images = [f.replace('\\', '/') for f in images]
|
||||
else:
|
||||
# this is the choice where image_record.is_packed is true
|
||||
# meaning that the image data can be stored in the blend data
|
||||
# This happens when the image is retrieved from the binary data
|
||||
# in a glTF/glb
|
||||
images = [ image_record.url ]
|
||||
# note: the following has the effect of eliminating duplicate paths
|
||||
# while preserving order-priority
|
||||
image_urls = [f for i, f in enumerate(images) if f not in images[:i]]
|
||||
|
||||
# note: the following has the effect of eliminating duplicate paths
|
||||
# while preserving order-priority
|
||||
images = [f for i, f in enumerate(images) if f not in images[:i]]
|
||||
logger.info("node urls: %s" % (images,))
|
||||
fw(ident_step + "url='%s'\n" % ' '.join(['"%s"' % escape(f) for f in images]))
|
||||
logger.info("node urls: %s" % (image_urls,))
|
||||
fw(ident_step + "url='%s'\n" % ' '.join(['"%s"' % escape(f) for f in image_urls]))
|
||||
|
||||
# default value of repeatS, repeatT fields is true, so only need to
|
||||
# specify if extension value is CLIP
|
||||
if image_record.extension == CLIP:
|
||||
x3d_supported_extension = ["CLIP", "REPEAT"]
|
||||
if imageTextureNode.extension not in x3d_supported_extension:
|
||||
logger.warn("imageTextureNode.extension value %s unsupported in X3D" % imageTextureNode.extension)
|
||||
|
||||
if imageTextureNode.extension == "CLIP":
|
||||
fw(ident_step + "repeatS='false' repeatT='false'")
|
||||
fw(ident_step + '/>\n')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
why is this temporary folder needed? Could you add that to the comment?