Skip to content

Commit

Permalink
Unit test for removal of "compositeTest" and code. Also, the removal …
Browse files Browse the repository at this point in the history
…of all unit tests and files related to the composite feature, long marked disabled.
  • Loading branch information
tngreene committed Jun 5, 2020
1 parent d124308 commit d84881d
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 285 deletions.
2 changes: 1 addition & 1 deletion io_xplane2blender/xplane_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# The current data model version, incrementing every time xplane_constants, xplane_props, or xplane_updater
# changes. Builds earlier than 3.4.0-beta.5 have and a version of 0.
# When merging, take the higher data model version of the two branches and add one
CURRENT_DATA_MODEL_VERSION = 75
CURRENT_DATA_MODEL_VERSION = 76

# The build number, hardcoded by the build script when there is one, otherwise it is xplane_constants.BUILD_NUMBER_NONE
CURRENT_BUILD_NUMBER = xplane_constants.BUILD_NUMBER_NONE
Expand Down
97 changes: 0 additions & 97 deletions io_xplane2blender/xplane_image_composer.py

This file was deleted.

6 changes: 0 additions & 6 deletions io_xplane2blender/xplane_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,12 +1334,6 @@ class XPlaneSceneSettings(bpy.types.PropertyGroup):
]
)

compositeTextures: bpy.props.BoolProperty(
name = "Compile Normal-Textures",
description = "Will automatically create and use corrected normal textures",
default = True
)

# This list of version histories the .blend file has encountered,
# from the earliest
xplane2blender_ver_history: bpy.props.CollectionProperty(
Expand Down
68 changes: 2 additions & 66 deletions io_xplane2blender/xplane_types/xplane_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@

from ..xplane_constants import *
from ..xplane_helpers import floatToStr, logger, resolveBlenderPath
from ..xplane_image_composer import (combineSpecularAndNormal,
getImageByFilepath, normalWithoutAlpha,
specularToGrayscale)

from .xplane_attribute import XPlaneAttribute
from .xplane_attributes import XPlaneAttributes

from typing import List

class XPlaneHeader():
'''
Writes OBJ info related to the OBJ8 header, such as POINT_COUNTS and TEXTURE.
Also the starting point for is responsible for autodetecting and compositing textures.
'''
"""Writes OBJ8 header properties such as TEXTURE, GLOBAL_*, and many others"""

def __init__(self, xplaneFile: 'XPlaneFile', obj_version: int)->None:
self.obj_version = obj_version
Expand Down Expand Up @@ -381,65 +376,6 @@ def _compositeNormalTextureNeedsRecompile(self, compositePath, sourcePaths):

return False

def _getCompositeNormalTexture(self, textureNormal, textureSpecular):
normalImage = None
specularImage = None
texture = None
image = None
filepath = None
channels = 4

if textureNormal:
normalImage = getImageByFilepath(textureNormal)

if textureSpecular:
specularImage = getImageByFilepath(textureSpecular)

# only normals, no specular
if normalImage and not specularImage:
filename, extension = os.path.splitext(textureNormal)
filepath = texture = filename + '_nm' + extension
channels = 3

if self._compositeNormalTextureNeedsRecompile(filepath, (textureNormal)):
image = normalWithoutAlpha(normalImage, normalImage.name + '_nm')

# normal + specular
elif normalImage and specularImage:
filename, extension = os.path.splitext(textureNormal)
filepath = texture = filename + '_nm_spec' + extension
channels = 4

if self._compositeNormalTextureNeedsRecompile(filepath, (textureNormal, textureSpecular)):
image = combineSpecularAndNormal(specularImage, normalImage, normalImage.name + '_nm_spec')

# specular only
elif not normalImage and specularImage:
filename, extension = os.path.splitext(textureSpecular)
filepath = texture = filename + '_spec' + extension
channels = 1

if self._compositeNormalTextureNeedsRecompile(filepath, (textureSpecular)):
image = specularToGrayscale(specularImage, specularImage.name + '_spec')

if image:
savepath = resolveBlenderPath(filepath)

color_mode = bpy.context.scene.render.image_settings.color_mode
if channels == 4:
bpy.context.scene.render.image_settings.color_mode = 'RGBA'
elif channels == 3:
bpy.context.scene.render.image_settings.color_mode = 'RGB'
elif channels == 1:
bpy.context.scene.render.image_settings.color_mode = 'BW'
image.save_render(savepath, bpy.context.scene)
image.filepath = filepath

# restore color_mode
bpy.context.scene.render.image_settings.color_mode = color_mode

return texture

# Method: getPathRelativeToOBJ
# Returns the resource path relative to the exported OBJ
#
Expand Down
1 change: 0 additions & 1 deletion io_xplane2blender/xplane_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def empty_layout(layout:bpy.types.UILayout, empty_obj:bpy.types.Object):
def scene_layout(layout:bpy.types.UILayout, scene:bpy.types.Scene):
layout.row().operator("scene.export_to_relative_dir", icon="EXPORT")
layout.row().prop(scene.xplane, "version")
layout.row().prop(scene.xplane, "compositeTextures")

xp2b_ver = xplane_helpers.VerStruct.current()
if xp2b_ver.build_type == xplane_constants.BUILD_TYPE_RC and xp2b_ver.build_number != xplane_constants.BUILD_NUMBER_NONE:
Expand Down
6 changes: 6 additions & 0 deletions io_xplane2blender/xplane_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ def update(last_version:xplane_helpers.VerStruct, logger:xplane_helpers.XPlaneLo
xplane_updater_helpers.delete_property_from_datablock(has_layer.xplane.layer, "export")
#----------------------------------------------------------------------

#TODO: Must replace with real build number of beta.3, when we get there
if last_version < xplane_helpers.VerStruct.parse_version("4.0.0-dev.0+76.20200605105300"):
for scene in bpy.data.scenes:
xplane_updater_helpers.delete_property_from_datablock(scene.xplane, "compositeTextures")


@persistent
def load_handler(dummy):
filepath = bpy.context.blend_data.filepath
Expand Down
Binary file removed tests/features/tex/color.png
Binary file not shown.
Binary file removed tests/features/tex/draped.png
Binary file not shown.
Binary file removed tests/features/tex/draped_NML.png
Binary file not shown.
Binary file removed tests/features/tex/normal.png
Binary file not shown.
Binary file removed tests/features/tex/normal_with_alpha.png
Binary file not shown.
Binary file removed tests/features/tex/specular.png
Binary file not shown.
Binary file removed tests/features/texture_composition.test.blend
Binary file not shown.
114 changes: 0 additions & 114 deletions tests/features/texture_composition.test.disabled.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/updater/removed_composite_textures.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import inspect

from typing import Tuple
import os
import sys

import bpy
from io_xplane2blender import xplane_config
from io_xplane2blender.tests import *
from io_xplane2blender.tests import test_creation_helpers

__dirname__ = os.path.dirname(__file__)

class TestRemovedCompositeTextures(XPlaneTestCase):
def test_remove_composite_textures(self)->None:
self.assertRaises(AttributeError, lambda: bpy.context.scene.xplane.compositeTextures)
self.assertFalse("compositeTextures" in bpy.context.scene.xplane)

runTestCases([TestRemovedCompositeTextures])

0 comments on commit d84881d

Please sign in to comment.