Skip to content

Commit

Permalink
Merge pull request #60 from soupday/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
soupday authored Aug 29, 2024
2 parents b133b9f + 0536d1c commit a0ef8aa
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Known Issues
Changelog
=========

### 2.1.7
- Normal maps imported separately from batch substance import as it does not correctly assign to Normal channel under certain circumstances.
- Sync lights includes scene IBL from visual settings.

### 2.1.6
- Export supports selection of multiple objects.
- When exporting multiple objects, the exporter will create a folder and export each individual object to that folder.
Expand Down
8 changes: 5 additions & 3 deletions btp/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class SkinBoneType(IntEnum):
"Refraction": [EMaterialTextureChannel_Refraction, False, ""],
"Cube": [EMaterialTextureChannel_Cube, False, ""],
"AO": [EMaterialTextureChannel_AmbientOcclusion, True, "ao"],
"Bump": [EMaterialTextureChannel_Bump, True, "bump"],
"Normal": [EMaterialTextureChannel_Normal, True, "normal"],
"Bump": [EMaterialTextureChannel_Bump, False, "bump"],
"Normal": [EMaterialTextureChannel_Normal, False, "normal"],
}


Expand Down Expand Up @@ -715,7 +715,9 @@ def set_shader(self, shader):
if material_component:
if shader in SHADER_MAPS:
shader_full_name = SHADER_MAPS[shader]
material_component.SetShader(self.mesh_name, self.mat_name, shader_full_name)
result = material_component.SetShader(self.mesh_name, self.mat_name, shader_full_name)
return (result == RStatus.Success)
return False

def load_channel_image(self, channel, file):
material_component = self.material_component()
Expand Down
7 changes: 6 additions & 1 deletion btp/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ def update_shaders(self, cc_mesh_materials):
if wanted_shader == "RLSSS" and M.mat_name.startswith("Ga_Skin_"):
wanted_shader = "Pbr"
if current_shader != wanted_shader:
M.set_shader(wanted_shader)
utils.log_info(f"Changing shader ({M.obj_name} / {M.mat_name}): {current_shader} to {wanted_shader}")
if not M.set_shader(wanted_shader):
utils.log_info(f" - Failed to set shader!")

# Calculate stats
num_materials += 1
Expand Down Expand Up @@ -457,6 +459,9 @@ def import_substance_textures(self, mesh_materials):
if not os.path.exists(temp_folder):
os.mkdir(temp_folder)

if vars.DEV:
os.startfile(temp_folder)

F: cc.CCMeshMaterial = None
M: cc.CCMeshMaterial = None

Expand Down
73 changes: 64 additions & 9 deletions btp/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,15 @@ def parse(self, op_code, data):
self.keepalive_timer = KEEPALIVE_TIMEOUT_S
if op_code == OpCodes.HELLO:
utils.log_info(f"Hello Received")
self.service_initialize()
if data:
json_data = decode_to_json(data)
self.remote_app = json_data["Application"]
self.remote_version = json_data["Version"]
self.remote_path = json_data["Path"]
utils.log_info(f"Connected to: {self.remote_app} {self.remote_version}")
utils.log_info(f"Using file path: {self.remote_path}")
self.service_initialize()
if data:
self.changed.emit()
elif op_code == OpCodes.PING:
utils.log_info(f"Ping Received")
Expand Down Expand Up @@ -1829,14 +1830,19 @@ def get_remote_folder(self):
else:
return "None"

def get_export_path(self, character_name, file_name):
def get_export_path(self, folder_name, file_name, unique=True):
if self.service:
if self.service.remote_path:
export_folder = utils.make_sub_folder(self.service.remote_path, "imports")
else:
export_folder = utils.make_sub_folder(self.service.local_path, "imports")

character_export_folder = utils.get_unique_folder_path(export_folder, character_name, create=True)
if unique:
character_export_folder = utils.get_unique_folder_path(export_folder, folder_name, create=True)
else:
character_export_folder = os.path.join(export_folder, folder_name)
if not os.path.exists(character_export_folder):
os.makedirs(character_export_folder, exist_ok=True)
export_path = os.path.join(character_export_folder, file_name)
return export_path
return "None"
Expand Down Expand Up @@ -2423,20 +2429,69 @@ def get_lights_data(self, lights):

return data

def encode_lights_data(self, lights):
data = self.get_lights_data(lights)
return encode_from_json(data)

def get_all_lights(self):
lights = RScene.FindObjects(EObjectType_Light)
return lights

def export_hdri(self, lights_data):
VSC: RIVisualSettingComponent = RGlobal.GetVisualSettingComponent()
use_ibl = VSC.IsIBLEnable() and VSC.IsValid()
lights_data["use_ibl"] = use_ibl
try:
ambient_color: RRgb = VSC.GetAmbientColor()
except:
ambient_color = RRgb(0.2,0.2,0.2)
if use_ibl:
export_path = self.get_export_path("Lighting Settings", "RL_Scene_HDRI.hdr", unique=False)
if os.path.exists(export_path):
try:
os.remove(export_path)
except:
pass
utils.log_info(f"Export HDRI: {export_path}")
VSC.SaveIBLImage(export_path)
lights_data["ibl_path"] = export_path
# TODO need API to get IBl strength (and blur)
# ibl_strength = VSC.GetIBLStrength()
# for now set to ambient color average
ambient_strength = (ambient_color.R() + ambient_color.G() + ambient_color.B()) / 3
ibl_strength = (0.5 + ambient_strength) / 2
lights_data["ibl_strength"] = ibl_strength
# TODO need API to get IBL transform
# ibl_transform = VSC.GetIBLTransform()
# or...
# ibl_location = VSC.GetIBLTranslation()
# ibl_rotation = VSC.GetIBLRotation()
# ibl_scale = VSC.GetIBLScale()
# for now get from the sky (which is not updated by the IBL settings, but better than nothing)
ibl_location = RVector3(0,0,0)
ibl_rotation = [ 0.0, 0.0, 0.0 ]
ibl_scale = RVector3(1,1,1)
if True: #VSC.IsIBLSyncSkyOrientation():
sky: RISky = RScene.FindObject(EObjectType_Sky, "Sky")
T: RTransform = sky.WorldTransform()
t: RVector3 = T.T()
r: RQuaternion = T.R()
s: RVector3 = T.S()
rot_matrix: RMatrix3 = r.ToRotationMatrix()
x = y = z = 0
euler = rot_matrix.ToEulerAngle(EEulerOrder_XYZ, x, y, z)
ibl_location = t
ibl_rotation = [ euler[0], euler[1], euler[2] - 96.5*0.01745329 ]
ibl_scale = s
lights_data["ibl_location"] = [ ibl_location.x,
ibl_location.y,
ibl_location.z - 96.5*0.01745329 ]
lights_data["ibl_rotation"] = ibl_rotation
lights_data["ibl_scale"] = ibl_scale.x

def sync_lights(self):
self.update_link_status(f"Synchronizing Lights")
self.send_notify(f"Sync Lights")
lights = self.get_all_lights()
lights_data = self.encode_lights_data(lights)
self.send(OpCodes.LIGHTS, lights_data)
lights_data = self.get_lights_data(lights)
self.export_hdri(lights_data)
self.send(OpCodes.LIGHTS, encode_from_json(lights_data))

def get_camera_data(self, camera: RICamera):
link_id = cc.get_link_id(camera, add_if_missing=True)
Expand Down
2 changes: 1 addition & 1 deletion btp/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from RLPy import *

VERSION = "2.1.6"
VERSION = "2.1.7"
DEV = False

AVATAR_TYPES = {
Expand Down

0 comments on commit a0ef8aa

Please sign in to comment.