feat: update BME prototypes

- update BMe prototypes. add chris suggested component for future changes.
- add new 2 custom function in BME environment.
This commit is contained in:
yyc12345 2025-01-18 19:09:32 +08:00
parent c448216496
commit 4a96906002
3 changed files with 599 additions and 36 deletions

View File

@ -88,6 +88,25 @@ def _get_prototype_by_identifier(ident: str) -> dict[str, typing.Any]:
#region Programmable Field Calc
def _env_fct_distance(x1: float, y1: float, x2: float, y2: float) -> float:
diff = mathutils.Vector((x2, y2)) - mathutils.Vector((x1, y1))
return diff.length
def _env_fct_angle(x1: float, y1: float, x2: float, y2: float) -> float:
# compute blender angle first
# computed blender angle has some issues:
# first, it is range from -180 to 180 (0 is +X axis).
# second, its direction (clockwise is positive) is opposite with blender rotation direction (counter-clockwise is positive).
diff = mathutils.Vector((x2, y2)) - mathutils.Vector((x1, y1))
bld_angle = math.degrees(mathutils.Vector((1,0)).angle_signed(diff, 0))
# flip it first
bld_angle = -bld_angle
# process positove number and negative number respectively
# to let it range change from -180~180 to 0~360
if bld_angle > 0: return bld_angle
else: return 360 + bld_angle
_g_ProgFieldGlobals: dict[str, typing.Any] = {
# constant
'pi': math.pi,
@ -122,6 +141,10 @@ _g_ProgFieldGlobals: dict[str, typing.Any] = {
'rot': lambda x, y, z: mathutils.Matrix.LocRotScale(None, mathutils.Euler((math.radians(x), math.radians(y), math.radians(z)), 'XYZ'), None),
'scale': lambda x, y, z: mathutils.Matrix.LocRotScale(None, None, (x, y, z)),
'ident': lambda: mathutils.Matrix.Identity(4),
# my misc custom functions
'distance': _env_fct_distance,
'angle': _env_fct_angle,
}
def _eval_showcase_cfgs_default(strl: str) -> typing.Any:

View File

@ -0,0 +1,398 @@
[
{
"identifier": "cv_trapezoid_side",
"showcase": null,
"params": [
{
"field": "long_edge_length",
"data": "5.0"
},
{
"field": "short_edge_offset",
"data": "0.0"
},
{
"field": "short_edge_length",
"data": "5.0"
},
{
"field": "height",
"data": "5.0"
},
{
"field": "face",
"data": "(True, False, False, False, True, False)"
},
{
"field": "is_sink",
"data": "False"
},
{
"field": "is_ribbon",
"data": "False"
}
],
"skip": "long_edge_length == 0.0 or short_edge_length == 0.0",
"vars": [
{
"field": "long_edge_uv_length",
"data": "long_edge_length / 5.0"
},
{
"field": "short_edge_uv_offset",
"data": "short_edge_offset / 5.0"
},
{
"field": "short_edge_uv_length",
"data": "short_edge_length / 5.0"
},
{
"field": "short_edge_total",
"data": "short_edge_offset + short_edge_length"
},
{
"field": "short_edge_uv_total",
"data": "short_edge_uv_offset + short_edge_uv_length"
},
{
"field": "uv_border_texture",
"data": "1.0 if is_ribbon else 0.5"
},
{
"field": "sink",
"data": "0.7 if is_sink else 0.0"
}
],
"vertices": [
{
"skip": "not face[0]",
"data": "(0, 0, 0)"
},
{
"skip": "not face[0]",
"data": "(short_edge_offset, 2.5, -sink)"
},
{
"skip": "not face[0]",
"data": "(long_edge_length, 0, 0)"
},
{
"skip": "not face[0]",
"data": "(short_edge_total, 2.5, -sink)"
}
],
"faces": [
{
"skip": "not face[0]",
"texture": "(\"FloorTopFlat\" if is_ribbon else \"FloorTopProfil\") if is_sink else \"FloorTopBorder\"",
"indices": [0, 2, 3, 1],
"uvs": [
"(0, 0)",
"(0, long_edge_uv_length)",
"(uv_border_texture, short_edge_uv_total)",
"(uv_border_texture, short_edge_uv_offset)"
],
"normals": null
}
],
"instances": [
{
"identifier": "raw_floor_side",
"skip": "not face[4]",
"params": {
"height": "height",
"length": "long_edge_length",
"is_left_sink": "False",
"is_right_sink": "False"
},
"transform": "ident()"
},
{
"identifier": "raw_floor_side",
"skip": "not face[2]",
"params": {
"height": "height",
"length": "distance(0, 0, short_edge_offset, 2.5)",
"is_left_sink": "is_sink",
"is_right_sink": "False"
},
"transform": "rot(0, 0, angle(0, 0, short_edge_offset, 2.5)) @ scale(1, -1, 1)"
},
{
"identifier": "raw_floor_side",
"skip": "not face[3]",
"params": {
"height": "height",
"length": "distance(long_edge_length, 0, short_edge_total, 2.5)",
"is_left_sink": "False",
"is_right_sink": "is_sink"
},
"transform": "move(long_edge_length, 0, 0) @ rot(0, 0, angle(long_edge_length, 0, short_edge_total, 2.5))"
},
{
"identifier": "raw_floor_side",
"skip": "not face[5]",
"params": {
"height": "height",
"length": "length",
"is_left_sink": "is_sink",
"is_right_sink": "is_sink"
},
"transform": "move(short_edge_offset, 2.5, 0) @ scale(1, -1, 1)"
},
{
"identifier": "floor_4edges_bottom",
"skip": "not face[1]",
"params": {
"top_left_pos": "(0, 0)",
"top_right_pos": "(short_edge_offset, 2.5)",
"bottom_left_pos": "(long_edge_length, 0)",
"bottom_right_pos": "(short_edge_total, 2.5)"
},
"transform": "move(0, 0, -height)"
}
]
},
{
"identifier": "cv_triangle_side",
"showcase": null,
"params": [
{
"field": "height",
"data": "5.0"
},
{
"field": "face",
"data": "(True, False, False, False, True, None)"
},
{
"field": "is_sink",
"data": "False"
}
],
"skip": "False",
"vars": [
{
"field": "sink",
"data": "0.7 if is_sink else 0.0"
}
],
"vertices": [
{
"skip": "not face[0]",
"data": "(0, 0, 0)"
},
{
"skip": "not face[0]",
"data": "(2.5, 2.5, -sink)"
},
{
"skip": "not face[0]",
"data": "(5.0, 0, 0)"
}
],
"faces": [
{
"skip": "not face[0]",
"texture": "\"FloorTopProfil\" if is_sink else \"FloorTopBorder\"",
"indices": [0, 2, 1],
"uvs": [
"(0, 0)",
"(0, 1)",
"(0.5, 0.5)"
],
"normals": null
}
],
"instances": [
{
"identifier": "raw_floor_side",
"skip": "not face[4]",
"params": {
"height": "height",
"length": "5",
"is_left_sink": "False",
"is_right_sink": "False"
},
"transform": "ident()"
},
{
"identifier": "raw_floor_side",
"skip": "not face[2]",
"params": {
"height": "height",
"length": "distance(0, 0, 2.5, 2.5)",
"is_left_sink": "is_sink",
"is_right_sink": "False"
},
"transform": "rot(0, 0, 45) @ scale(1, -1, 1)"
},
{
"identifier": "raw_floor_side",
"skip": "not face[3]",
"params": {
"height": "height",
"length": "distance(5, 0, 2.5, 2.5)",
"is_left_sink": "False",
"is_right_sink": "is_sink"
},
"transform": "move(5, 0, 0) @ rot(0, 0, 135)"
},
{
"identifier": "floor_triangle_bottom",
"skip": "not face[1]",
"params": {
"length": "5.0",
"width": "2.5",
"tip_offset": "2.5"
},
"transform": "move(0, 0, -height)"
}
]
},
{
"identifier": "cv_triangle_center",
"showcase": null,
"params": [
{
"field": "height",
"data": "5.0"
},
{
"field": "face",
"data": "(True, False, False, None, False, False)"
},
{
"field": "is_sink",
"data": "False"
}
],
"skip": "False",
"vars": [
{
"field": "sink",
"data": "0.7 if is_sink else 0.0"
}
],
"vertices": [
{
"skip": "not face[0]",
"data": "(0, 0, 0)"
},
{
"skip": "not face[0]",
"data": "(0, 5, 0)"
},
{
"skip": "not face[0]",
"data": "(2.5, 2.5, -sink)"
},
{
"skip": "(not face[0]) and is_sink",
"data": "(0, 2.5, -sink)"
}
],
"faces": [
{
"skip": "(not face[0]) and (not is_sink)",
"texture": "\"FloorTopFlat\"",
"indices": [0, 2, 1],
"uvs": [
"(0, 0)",
"(0.5, 0.5)",
"(1, 0)"
],
"normals": null
},
{
"skip": "(not face[0]) and is_sink",
"texture": "\"FloorTopFlat\"",
"indices": [0, 2, 3],
"uvs": [
"(0, 0)",
"(0.5, 0.5)",
"(0.5, 0)"
],
"normals": null
},
{
"skip": "(not face[0]) and is_sink",
"texture": "\"FloorTopFlat\"",
"indices": [3, 2, 1],
"uvs": [
"(0.5, 0)",
"(0.5, 0.5)",
"(1, 0)"
],
"normals": null
}
],
"instances": [
{
"identifier": "raw_floor_side",
"skip": "not face[4]",
"params": {
"height": "height",
"length": "distance(0, 0, 2.5, 2.5)",
"is_left_sink": "False",
"is_right_sink": "is_sink"
},
"transform": "rot(0, 0, 45)"
},
{
"identifier": "raw_floor_side",
"skip": "not face[5]",
"params": {
"height": "height",
"length": "distance(5, 0, 2.5, 2.5)",
"is_left_sink": "is_sink",
"is_right_sink": "False"
},
"transform": "move(2.5, 2.5, 0) @ rot(0, 0, 135)"
},
{
"identifier": "raw_floor_side",
"skip": "(not face[2]) and is_sink",
"params": {
"height": "height",
"length": "2.5",
"is_left_sink": "False",
"is_right_sink": "True"
},
"transform": "rot(0, 0, 90) @ scale(1, -1 , 1)"
},
{
"identifier": "raw_floor_side",
"skip": "(not face[2]) and is_sink",
"params": {
"height": "height",
"length": "2.5",
"is_left_sink": "True",
"is_right_sink": "False"
},
"transform": "move(0, 2.5, 0) @ rot(0, 0, 90) @ scale(1, -1 , 1)"
},
{
"identifier": "raw_floor_side",
"skip": "(not face[2]) and (not is_sink)",
"params": {
"height": "height",
"length": "5",
"is_left_sink": "False",
"is_right_sink": "False"
},
"transform": "rot(0, 0, 90) @ scale(1, -1 , 1)"
},
{
"identifier": "floor_triangle_bottom",
"skip": "not face[1]",
"params": {
"length": "5",
"width": "2.5",
"tip_offset": "2.5"
},
"transform": "move(0, 5, -height) @ rot(0, 0, -90)"
}
]
}
]

View File

@ -122,7 +122,142 @@
"instances": []
},
{
"identifier": "floor_bottom",
"identifier": "floor_4edges_bottom",
"showcase": null,
"params": [
{
"field": "top_left_pos",
"data": "(0.0, 0.0)"
},
{
"field": "top_right_pos",
"data": "(0.0, 5.0)"
},
{
"field": "bottom_left_pos",
"data": "(5.0, 0.0)"
},
{
"field": "bottom_right_pos",
"data": "(5.0, 5.0)"
}
],
"skip": "False",
"vars": [
{
"field": "top_left_uv",
"data": "tuple(map(lambda x: x / 5.0, top_left_pos))"
},
{
"field": "top_right_uv",
"data": "tuple(map(lambda x: x / 5.0, top_right_pos))"
},
{
"field": "bottom_left_uv",
"data": "tuple(map(lambda x: x / 5.0, bottom_left_pos))"
},
{
"field": "bottom_right_uv",
"data": "tuple(map(lambda x: x / 5.0, bottom_right_pos))"
}
],
"vertices": [
{
"skip": "False",
"data": "top_left_pos + (0, )"
},
{
"skip": "False",
"data": "top_right_pos + (0, )"
},
{
"skip": "False",
"data": "bottom_left_pos + (0, )"
},
{
"skip": "False",
"data": "bottom_right_pos + (0, )"
}
],
"faces": [
{
"skip": "False",
"texture": "\"FloorTopBorderless\"",
"indices": [0, 1, 3, 2],
"uvs": [
"top_left_uv",
"top_right_uv",
"bottom_right_uv",
"bottom_left_uv"
],
"normals": null
}
],
"instances": []
},
{
"identifier": "floor_3edges_bottom",
"showcase": null,
"params": [
{
"field": "top_pos",
"data": "(0.0, 0.0)"
},
{
"field": "bottom_pos",
"data": "(5.0, 0.0)"
},
{
"field": "tip_pos",
"data": "(2.5, 2.5)"
}
],
"skip": "False",
"vars": [
{
"field": "top_uv",
"data": "tuple(map(lambda x: x / 5.0, top_pos))"
},
{
"field": "bottom_uv",
"data": "tuple(map(lambda x: x / 5.0, bottom_pos))"
},
{
"field": "tip_uv",
"data": "tuple(map(lambda x: x / 5.0, tip_pos))"
}
],
"vertices": [
{
"skip": "False",
"data": "top_pos + (0, )"
},
{
"skip": "False",
"data": "bottom_pos + (0, )"
},
{
"skip": "False",
"data": "tip_pos + (0, )"
}
],
"faces": [
{
"skip": "False",
"texture": "\"FloorTopBorderless\"",
"indices": [0, 2, 1],
"uvs": [
"top_uv",
"tip_uv",
"bottom_uv"
],
"normals": null
}
],
"instances": []
},
{
"identifier": "floor_rectangle_bottom",
"showcase": null,
"params": [
{
@ -135,48 +270,55 @@
}
],
"skip": "length == 0.0 or width == 0.0",
"vars": [
"vars": [],
"vertices": [],
"faces": [],
"instances": [
{
"field": "uv_length",
"data": "length / 5.0"
"identifier": "floor_4edges_bottom",
"skip": "False",
"params": {
"top_left_pos": "(0, 0)",
"top_right_pos": "(0, width)",
"bottom_left_pos": "(length, 0)",
"bottom_right_pos": "(length, width)"
},
"transform": "ident()"
}
]
},
{
"identifier": "floor_triangle_bottom",
"showcase": null,
"params": [
{
"field": "length",
"data": "5.0"
},
{
"field": "uv_width",
"data": "width / 5.0"
"field": "width",
"data": "2.5"
},
{
"field": "tip_offset",
"data": "2.5"
}
],
"vertices": [
"skip": "length == 0.0",
"vars": [],
"vertices": [],
"faces": [],
"instances": [
{
"identifier": "floor_3edges_bottom",
"skip": "False",
"data": "(0, 0, 0)"
},
{
"skip": "False",
"data": "(0, width, 0)"
},
{
"skip": "False",
"data": "(length, 0, 0)"
},
{
"skip": "False",
"data": "(length, width, 0)"
"params": {
"top_pos": "(0, 0)",
"bottom_pos": "(length, 0)",
"tip_pos": "(tip_offset, width)"
},
"transform": "ident()"
}
],
"faces": [
{
"skip": "False",
"texture": "\"FloorTopBorderless\"",
"indices": [0, 1, 3, 2],
"uvs": [
"(0, 0)",
"(uv_width, 0)",
"(uv_width, uv_length)",
"(0, uv_length)"
],
"normals": null
}
],
"instances": []
]
}
]