Compare commits

...

2 Commits

Author SHA1 Message Date
8105b110f2 feat: add default rail material when creating rail.
- add default rail material when creating rail.
	* add Rail material in bme material.
- remove negative screw radius feature when creating curve rail.
	* originally negative screw radius will cause normal flip issue when creating.
	* however, negative screw radius feature can no fulfill each shapes of screw style. it is more convenient using blender mirror feature after creating screw rail.
	* thus I remove this feature, not fix it (I can fix it).
2025-01-04 12:28:59 +08:00
acb87b3844 fix: fix step count error when exporting virtools file 2025-01-04 10:19:31 +08:00
3 changed files with 26 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import bpy, bmesh, mathutils, math import bpy, bmesh, mathutils, math
import typing import typing
from . import UTIL_functions, UTIL_naming_convension from . import UTIL_functions, UTIL_naming_convension
from . import PROP_bme_material
## Const Value Hint: ## Const Value Hint:
# Default Rail Radius: 0.35 (in measure) # Default Rail Radius: 0.35 (in measure)
@ -162,8 +163,9 @@ class SharedScrewRailInputProperty():
rail_screw_radius: bpy.props.FloatProperty( rail_screw_radius: bpy.props.FloatProperty(
name = "Radius", name = "Radius",
description = "The screw radius. Minus radius will flip the built screw.", description = "The screw radius.",
default = 5, default = 5,
min = 0,
unit = 'LENGTH' unit = 'LENGTH'
) # type: ignore ) # type: ignore
@ -441,7 +443,10 @@ class BBP_OT_add_side_spiral_rail(SharedExtraTransform, SharedRailSectionInputPr
#region BMesh Operations Helper #region BMesh Operations Helper
def _bmesh_extrude(bm: bmesh.types.BMesh, start_edges: list[bmesh.types.BMEdge], direction: mathutils.Vector) -> list[bmesh.types.BMEdge]: def _bmesh_extrude(
bm: bmesh.types.BMesh,
start_edges: list[bmesh.types.BMEdge],
direction: mathutils.Vector) -> list[bmesh.types.BMEdge]:
# extrude # extrude
ret: dict[str, typing.Any] = bmesh.ops.extrude_edge_only( ret: dict[str, typing.Any] = bmesh.ops.extrude_edge_only(
bm, bm,
@ -485,7 +490,7 @@ def _bmesh_screw(
space = mathutils.Matrix.Identity(4), space = mathutils.Matrix.Identity(4),
steps = steps * iterations, steps = steps * iterations,
use_merge = False, use_merge = False,
use_normal_flip = True, # NOTE: flip nml according to real test result use_normal_flip = True, # NOTE: flip normal according to test result.
use_duplicate = False use_duplicate = False
) )
@ -539,6 +544,12 @@ def _rail_creator_wrapper(fct_poly_cret: typing.Callable[[bmesh.types.BMesh], No
# setup smooth for mesh # setup smooth for mesh
mesh.shade_smooth() mesh.shade_smooth()
# setup default material
with PROP_bme_material.BMEMaterialsHelper(bpy.context.scene) as bmemtl:
mesh.materials.clear()
mesh.materials.append(bmemtl.get_material('Rail'))
mesh.validate_material_indices()
# create object and assoc with it # create object and assoc with it
# create info first # create info first
rail_info: UTIL_naming_convension.BallanceObjectInfo = UTIL_naming_convension.BallanceObjectInfo.create_from_others( rail_info: UTIL_naming_convension.BallanceObjectInfo = UTIL_naming_convension.BallanceObjectInfo.create_from_others(
@ -662,7 +673,9 @@ def _create_straight_rail(
start_edges: list[bmesh.types.BMEdge] = bm.edges[:] start_edges: list[bmesh.types.BMEdge] = bm.edges[:]
# extrude and get end edges # extrude and get end edges
end_edges: list[bmesh.types.BMEdge] = _bmesh_extrude( end_edges: list[bmesh.types.BMEdge] = _bmesh_extrude(
bm, start_edges, mathutils.Vector((0, rail_length, 0)) bm,
start_edges,
mathutils.Vector((0, rail_length, 0))
) )
# smooth geometry # smooth geometry
@ -693,7 +706,9 @@ def _create_transition_rail(
start_edges: list[bmesh.types.BMEdge] = bm.edges[:] start_edges: list[bmesh.types.BMEdge] = bm.edges[:]
# extrude and get end edges # extrude and get end edges
end_edges: list[bmesh.types.BMEdge] = _bmesh_extrude( end_edges: list[bmesh.types.BMEdge] = _bmesh_extrude(
bm, start_edges, mathutils.Vector((0, rail_length, 0)) bm,
start_edges,
mathutils.Vector((0, rail_length, 0))
) )
# smooth geometry # smooth geometry

View File

@ -220,7 +220,7 @@ def _export_virtools_light(
light_crets: tuple[_TLightPair, ...] light_crets: tuple[_TLightPair, ...]
) -> None: ) -> None:
# start saving # start saving
progress.enter_substeps(0, "Saving Lights") progress.enter_substeps(len(light_crets), "Saving Lights")
for obj3d, light, vtlight in light_crets: for obj3d, light, vtlight in light_crets:
# set name # set name

View File

@ -63,6 +63,11 @@ _g_BMEMaterialPresets: dict[str, _BMEMaterialPreset] = {
'Ball_Wood.bmp', 'Ball_Wood.bmp',
PROP_virtools_material.get_virtools_material_preset(PROP_virtools_material.MaterialPresetType.TraforWoodStone).mData PROP_virtools_material.get_virtools_material_preset(PROP_virtools_material.MaterialPresetType.TraforWoodStone).mData
), ),
'Rail': _BMEMaterialPreset(
'Rail_Environment.bmp',
PROP_virtools_material.get_virtools_material_preset(PROP_virtools_material.MaterialPresetType.Rail).mData
),
} }
#endregion #endregion