本文整理汇总了Python中srctools.Vec.axis方法的典型用法代码示例。如果您正苦于以下问题:Python Vec.axis方法的具体用法?Python Vec.axis怎么用?Python Vec.axis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Vec
的用法示例。
在下文中一共展示了Vec.axis方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hole_spot
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import axis [as 别名]
def test_hole_spot(origin: Vec, normal: Vec, hole_type: HoleType):
"""Check if the given position is valid for holes.
We need to check that it's actually placed on glass/grating, and that
all the parts are the same. Otherwise it'd collide with the borders.
"""
try:
center_type = BARRIERS[origin.as_tuple(), normal.as_tuple()]
except KeyError:
LOGGER.warning('No center barrier at {}, {}', origin, normal)
return False
if hole_type is HoleType.SMALL:
return True
u, v = Vec.INV_AXIS[normal.axis()]
# The corners don't matter, but all 4 neighbours must be there.
for u_off, v_off in [
(-128, 0),
(0, -128),
(128, 0),
(0, 128),
]:
pos = origin + Vec.with_axes(u, u_off, v, v_off)
try:
off_type = BARRIERS[pos.as_tuple(), normal.as_tuple()]
except KeyError:
# No side
LOGGER.warning('No offset barrier at {}, {}', pos, normal)
return False
if off_type is not center_type:
# Different type.
LOGGER.warning('Wrong barrier type at {}, {}', pos, normal)
return False
return True
示例2: make_ubend
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import axis [as 别名]
def make_ubend(
origin_a: Vec,
origin_b: Vec,
normal: Vec,
config,
max_size: int,
is_start=False,
):
"""Create u-shaped bends."""
offset = origin_b - origin_a
out_axis = normal.axis()
out_off = offset[out_axis]
offset[out_axis] = 0
if len(offset) == 2:
# Len counts the non-zero values..
# If 2, the ubend is diagonal so it's ambigous where to put the bends.
return []
side_norm = offset.norm()
for side_axis, side_dist in zip('xyz', offset):
if side_dist:
side_dist = abs(side_dist) + 128
break
else:
# The two tube items are on top of another, that's
# impossible to generate.
return []
# Calculate the size of the various parts.
# first/second _size = size of the corners.
# first/second _straight = length of straight sections
# off_straight = length of straight in between corners
if out_off == 0:
# Both tubes are parallel to each other - use half the distance
# for the bends.
first_size = second_size = min(
3,
max_size,
side_dist // (128 * 2),
)
first_straight = second_straight = 0
side_straight = side_dist - 2 * 128 * first_size
elif out_off > 0:
# The second tube is further away than the first - the first bend
# should be largest.
# We need 1 spot for the second bend.
first_size = min(
3,
max_size,
side_dist // 128 - 1,
out_off,
)
second_size = min(3, side_dist // 128 - first_size, max_size)
first_straight = (out_off + 128) - 128 * second_size
second_straight = (first_size - second_size) * 128
side_straight = (side_dist / 128 - first_size - second_size) * 128
elif out_off < 0:
# The first tube is further away than the second - the second bend
# should be largest.
second_size = min(
3,
max_size,
side_dist // 128 - 1,
-out_off # -out = abs()
)
first_size = min(3, side_dist // 128 - second_size, max_size)
first_straight = (second_size - first_size) * 128
second_straight = (-out_off + 128) - 128 * second_size
side_straight = (side_dist / 128 - first_size - second_size) * 128
else:
return [] # Not possible..
# We always have a straight segment at the first marker point - move
# everything up slightly.
first_straight += 128
LOGGER.info(
'Ubend {}: {}, c={}, {}, c={}, {}',
out_off,
first_straight,
first_size,
side_straight,
second_size,
second_straight,
)
make_straight(
origin_a,
normal,
first_straight,
config,
#.........这里部分代码省略.........
示例3: make_barriers
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import axis [as 别名]
def make_barriers(vmf: VMF, get_tex: Callable[[str], str]):
"""Make barrier entities. get_tex is vbsp.get_tex."""
glass_temp = template_brush.get_scaling_template(
vbsp_options.get(str, "glass_template")
)
grate_temp = template_brush.get_scaling_template(
vbsp_options.get(str, "grating_template")
)
# Avoid error without this package.
if HOLES:
# Grab the template solids we need.
hole_temp = template_brush.get_template(
vbsp_options.get(str, 'glass_hole_temp')
)
hole_world, hole_detail, _ = hole_temp.visgrouped({'small'})
hole_temp_small = hole_world + hole_detail
hole_world, hole_detail, _ = hole_temp.visgrouped({'large'})
hole_temp_large = hole_world + hole_detail
hole_world, hole_detail, _ = hole_temp.visgrouped({'large_corner'})
hole_temp_corner = hole_world + hole_detail
else:
hole_temp_small = hole_temp_large = hole_temp_corner = None
floorbeam_temp = vbsp_options.get(str, 'glass_floorbeam_temp')
if vbsp_options.get_itemconf('BEE_PELLET:PelletGrating', False):
# Merge together these existing filters in global_pti_ents
vmf.create_ent(
origin=vbsp_options.get(Vec, 'global_pti_ents_loc'),
targetname='@grating_filter',
classname='filter_multi',
filtertype=0,
negated=0,
filter01='@not_pellet',
filter02='@not_paint_bomb',
)
else:
# Just skip paint bombs.
vmf.create_ent(
origin=vbsp_options.get(Vec, 'global_pti_ents_loc'),
targetname='@grating_filter',
classname='filter_activator_class',
negated=1,
filterclass='prop_paint_bomb',
)
# Group the positions by planes in each orientation.
# This makes them 2D grids which we can optimise.
# (normal_dist, positive_axis, type) -> [(x, y)]
slices = defaultdict(set) # type: Dict[Tuple[Tuple[float, float, float], bool, BarrierType], Set[Tuple[float, float]]]
# We have this on the 32-grid so we can cut squares for holes.
for (origin, normal), barr_type in BARRIERS.items():
origin = Vec(origin)
normal = Vec(normal)
norm_axis = normal.axis()
u, v = origin.other_axes(norm_axis)
norm_pos = Vec.with_axes(norm_axis, origin)
slice_plane = slices[
norm_pos.as_tuple(), # distance from origin to this plane.
normal[norm_axis] > 0,
barr_type,
]
for u_off in [-48, -16, 16, 48]:
for v_off in [-48, -16, 16, 48]:
slice_plane.add((
(u + u_off) // 32,
(v + v_off) // 32,
))
# Remove pane sections where the holes are. We then generate those with
# templates for slanted parts.
for (origin, normal), hole_type in HOLES.items():
barr_type = BARRIERS[origin, normal]
origin = Vec(origin)
normal = Vec(normal)
norm_axis = normal.axis()
u, v = origin.other_axes(norm_axis)
norm_pos = Vec.with_axes(norm_axis, origin)
slice_plane = slices[
norm_pos.as_tuple(),
normal[norm_axis] > 0,
barr_type,
]
if hole_type is HoleType.LARGE:
offsets = (-80, -48, -16, 16, 48, 80)
hole_temp = hole_temp_large.copy()
else:
offsets = (-16, 16)
hole_temp = hole_temp_small.copy()
for u_off in offsets:
for v_off in offsets:
# Skip the corners on large holes.
# Those aren't actually used, so skip them. That way
# we can have them diagonally or without glass in the corner.
if u_off in (-80, 80) and v_off in (-80, 80):
continue
slice_plane.discard((
#.........这里部分代码省略.........
示例4: make_frames
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import axis [as 别名]
def make_frames(vmf: VMF, targ: str, conf: dict, bbox_min: Vec, bbox_max: Vec, norm: Vec):
"""Generate frames for a rectangular glass item."""
def make_frame(frame_type, loc, angles):
"""Make a frame instance."""
vmf.create_ent(
classname='func_instance',
targetname=targ,
file=conf['frame_' + frame_type],
# Position at the center of the block, instead of at the glass.
origin=loc - norm * 64,
angles=angles,
)
if bbox_min == bbox_max:
# 1x1 glass..
make_frame('single', bbox_min, norm.to_angle())
return
norm_axis = norm.axis()
u_axis, v_axis = Vec.INV_AXIS[norm_axis]
u_norm = Vec()
v_norm = Vec()
u_norm[u_axis] = 1
v_norm[v_axis] = 1
single_u = bbox_min[u_axis] == bbox_max[u_axis]
single_v = bbox_min[v_axis] == bbox_max[v_axis]
# If single in either direction, it needs a u-bend.
if single_u:
ubend_axis = v_axis
elif single_v:
ubend_axis = u_axis
else:
ubend_axis = None
if ubend_axis is not None:
for bend_mag, bbox in [(1, bbox_min), (-1, bbox_max)]:
make_frame(
'ubend',
bbox,
norm.to_angle_roll(Vec.with_axes(ubend_axis, bend_mag)),
)
else:
# Make 4 corners - one in each roll direction.
for roll in range(0, 360, 90):
angles = norm.to_angle(roll)
# The two directions with a border in the corner instance.
# We want to put it on those sides.
corner_a = Vec(y=-1).rotate(*angles)
corner_b = Vec(z=-1).rotate(*angles)
# If the normal is positive, we want to be bbox_max in that axis,
# otherwise bbox_min.
pos = Vec.with_axes(
norm_axis, bbox_min,
corner_a.axis(),
(bbox_max if corner_a >= (0, 0, 0) else bbox_min),
corner_b.axis(),
(bbox_max if corner_b >= (0, 0, 0) else bbox_min),
)
make_frame(
'corner',
pos,
angles,
)
# Make straight sections.
straight_u_pos = norm.to_angle_roll(v_norm)
straight_u_neg = norm.to_angle_roll(-v_norm)
straight_v_pos = norm.to_angle_roll(u_norm)
straight_v_neg = norm.to_angle_roll(-u_norm)
for u_pos in range(int(bbox_min[u_axis] + 128), int(bbox_max[u_axis]), 128):
make_frame(
'edge',
Vec.with_axes(u_axis, u_pos, v_axis, bbox_min, norm_axis, bbox_min),
straight_u_pos,
)
make_frame(
'edge',
Vec.with_axes(u_axis, u_pos, v_axis, bbox_max, norm_axis, bbox_min),
straight_u_neg,
)
for v_pos in range(int(bbox_min[v_axis] + 128), int(bbox_max[v_axis]), 128):
make_frame(
'edge',
Vec.with_axes(v_axis, v_pos, u_axis, bbox_min, norm_axis, bbox_min),
straight_v_pos,
)
make_frame(
'edge',
Vec.with_axes(v_axis, v_pos, u_axis, bbox_max, norm_axis, bbox_min),
straight_v_neg,
)