forked from LeenkxTeam/LNXSDK
Blender 2.8 - 4.5 Support
This commit is contained in:
@ -15,7 +15,14 @@ from enum import Enum, unique
|
||||
import math
|
||||
import os
|
||||
import time
|
||||
from typing import Any, Dict, List, Tuple, Union, Optional
|
||||
from typing import Any, Dict, List, Tuple, Union, Optional, TYPE_CHECKING
|
||||
import bpy
|
||||
|
||||
|
||||
if bpy.app.version >= (3, 0, 0):
|
||||
VertexColorType = bpy.types.Attribute
|
||||
else:
|
||||
VertexColorType = bpy.types.MeshLoopColorLayer
|
||||
|
||||
import numpy as np
|
||||
|
||||
@ -138,7 +145,7 @@ class LeenkxExporter:
|
||||
self.world_array = []
|
||||
self.particle_system_array = {}
|
||||
|
||||
self.referenced_collections: list[bpy.types.Collection] = []
|
||||
self.referenced_collections: List[bpy.types.Collection] = []
|
||||
"""Collections referenced by collection instances"""
|
||||
|
||||
self.has_spawning_camera = False
|
||||
@ -1449,31 +1456,38 @@ class LeenkxExporter:
|
||||
@staticmethod
|
||||
def get_num_vertex_colors(mesh: bpy.types.Mesh) -> int:
|
||||
"""Return the amount of vertex color attributes of the given mesh."""
|
||||
num = 0
|
||||
for attr in mesh.attributes:
|
||||
if attr.data_type in ('BYTE_COLOR', 'FLOAT_COLOR'):
|
||||
if attr.domain == 'CORNER':
|
||||
num += 1
|
||||
else:
|
||||
log.warn(f'Only vertex colors with domain "Face Corner" are supported for now, ignoring "{attr.name}"')
|
||||
|
||||
return num
|
||||
if bpy.app.version >= (3, 0, 0):
|
||||
num = 0
|
||||
for attr in mesh.attributes:
|
||||
if attr.data_type in ('BYTE_COLOR', 'FLOAT_COLOR'):
|
||||
if attr.domain == 'CORNER':
|
||||
num += 1
|
||||
else:
|
||||
log.warn(f'Only vertex colors with domain "Face Corner" are supported for now, ignoring "{attr.name}"')
|
||||
return num
|
||||
else:
|
||||
return len(mesh.vertex_colors)
|
||||
|
||||
@staticmethod
|
||||
def get_nth_vertex_colors(mesh: bpy.types.Mesh, n: int) -> Optional[bpy.types.Attribute]:
|
||||
def get_nth_vertex_colors(mesh: bpy.types.Mesh, n: int) -> Optional[VertexColorType]:
|
||||
"""Return the n-th vertex color attribute from the given mesh,
|
||||
ignoring all other attribute types and unsupported domains.
|
||||
"""
|
||||
i = 0
|
||||
for attr in mesh.attributes:
|
||||
if attr.data_type in ('BYTE_COLOR', 'FLOAT_COLOR'):
|
||||
if attr.domain != 'CORNER':
|
||||
log.warn(f'Only vertex colors with domain "Face Corner" are supported for now, ignoring "{attr.name}"')
|
||||
continue
|
||||
if i == n:
|
||||
return attr
|
||||
i += 1
|
||||
return None
|
||||
if bpy.app.version >= (3, 0, 0):
|
||||
i = 0
|
||||
for attr in mesh.attributes:
|
||||
if attr.data_type in ('BYTE_COLOR', 'FLOAT_COLOR'):
|
||||
if attr.domain != 'CORNER':
|
||||
log.warn(f'Only vertex colors with domain "Face Corner" are supported for now, ignoring "{attr.name}"')
|
||||
continue
|
||||
if i == n:
|
||||
return attr
|
||||
i += 1
|
||||
return None
|
||||
else:
|
||||
if 0 <= n < len(mesh.vertex_colors):
|
||||
return mesh.vertex_colors[n]
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def check_uv_precision(mesh: bpy.types.Mesh, uv_max_dim: float, max_dim_uvmap: bpy.types.MeshUVLoopLayer, invscale_tex: float):
|
||||
@ -3094,7 +3108,18 @@ class LeenkxExporter:
|
||||
|
||||
rbw = self.scene.rigidbody_world
|
||||
if rbw is not None and rbw.enabled:
|
||||
out_trait['parameters'] = [str(rbw.time_scale), str(rbw.substeps_per_frame), str(rbw.solver_iterations), str(wrd.lnx_physics_fixed_step)]
|
||||
if hasattr(rbw, 'substeps_per_frame'):
|
||||
substeps = str(rbw.substeps_per_frame)
|
||||
elif hasattr(rbw, 'steps_per_second'):
|
||||
scene_fps = bpy.context.scene.render.fps
|
||||
substeps_per_frame = rbw.steps_per_second / scene_fps
|
||||
substeps = str(int(round(substeps_per_frame)))
|
||||
else:
|
||||
print("WARNING: Physics rigid body world cannot determine steps/substeps. Please report this for further investigation.")
|
||||
print("Setting steps to 10 [ low ]")
|
||||
substeps = '10'
|
||||
|
||||
out_trait['parameters'] = [str(rbw.time_scale), substeps, str(rbw.solver_iterations), str(wrd.lnx_physics_fixed_step)]
|
||||
|
||||
if phys_pkg == 'bullet' or phys_pkg == 'oimo':
|
||||
debug_draw_mode = 1 if wrd.lnx_physics_dbg_draw_wireframe else 0
|
||||
|
Reference in New Issue
Block a user