本文整理汇总了Python中srctools.Vec.bbox方法的典型用法代码示例。如果您正苦于以下问题:Python Vec.bbox方法的具体用法?Python Vec.bbox怎么用?Python Vec.bbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Vec
的用法示例。
在下文中一共展示了Vec.bbox方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calc_fizzler_orient
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
def calc_fizzler_orient(fizzler: Fizzler):
# Figure out how to compare for this fizzler.
s, l = Vec.bbox(itertools.chain.from_iterable(fizzler.emitters))
# If it's horizontal, signs should point to the center:
if abs(s.z - l.z) == 2:
return (
'z',
s.x + l.x / 2,
s.y + l.y / 2,
s.z + 1,
)
# For the vertical directions, we want to compare based on the line segment.
if abs(s.x - l.x) == 2: # Y direction
return (
'y',
s.y,
l.y,
s.x + 1,
)
else: # Extends in X direction
return (
'x',
s.x,
l.x,
s.y + 1,
)
示例2: make_straight
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
def make_straight(
origin: Vec,
normal: Vec,
dist: int,
config: dict,
is_start=False,
):
"""Make a straight line of instances from one point to another."""
# 32 added to the other directions, plus extended dist in the direction
# of the normal - 1
p1 = origin + (normal * ((dist // 128 * 128) - 96))
# The starting brush needs to
# stick out a bit further, to cover the
# point_push entity.
p2 = origin - (normal * (96 if is_start else 32))
# bbox before +- 32 to ensure the above doesn't wipe it out
p1, p2 = Vec.bbox(p1, p2)
solid = vbsp.VMF.make_prism(
# Expand to 64x64 in the other two directions
p1 - 32, p2 + 32,
mat='tools/toolstrigger',
).solid
motion_trigger(solid.copy())
push_trigger(origin, normal, [solid])
angles = normal.to_angle()
support_file = config['support']
straight_file = config['straight']
support_positions = (
SUPPORT_POS[normal.as_tuple()]
if support_file else
[]
)
for off in range(0, int(dist), 128):
position = origin + off * normal
vbsp.VMF.create_ent(
classname='func_instance',
origin=position,
angles=angles,
file=straight_file,
)
for supp_ang, supp_off in support_positions:
if (position + supp_off).as_tuple() in SOLIDS:
vbsp.VMF.create_ent(
classname='func_instance',
origin=position,
angles=supp_ang,
file=support_file,
)
示例3: flag_blockpos_type
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
def flag_blockpos_type(inst: Entity, flag: Property):
"""Determine the type of a grid position.
If the value is single value, that should be the type.
Otherwise, the value should be a block with 'offset' and 'type' values.
The offset is in block increments, with 0 0 0 equal to the mounting surface.
If 'offset2' is also provided, all positions in the bounding box will
be checked.
The type should be a space-seperated list of locations:
* `VOID` (Outside the map)
* `SOLID` (Full wall cube)
* `EMBED` (Hollow wall cube)
* `AIR` (Inside the map, may be occupied by items)
* `OCCUPIED` (Known to be occupied by items)
* `PIT` (Bottomless pits, any)
* `PIT_SINGLE` (one-high)
* `PIT_TOP`
* `PIT_MID`
* `PIT_BOTTOM`
* `GOO`
* `GOO_SINGLE` (one-deep goo)
* `GOO_TOP` (goo surface)
* `GOO_MID`
* `GOO_BOTTOM` (floor)
"""
pos2 = None
if flag.has_children():
pos1 = resolve_offset(inst, flag['offset', '0 0 0'], scale=128, zoff=-128)
types = flag['type'].split()
if 'offset2' in flag:
pos2 = resolve_offset(inst, flag.value, scale=128, zoff=-128)
else:
types = flag.value.split()
pos1 = Vec()
if pos2 is not None:
bbox = Vec.iter_grid(*Vec.bbox(pos1, pos2), stride=128)
else:
bbox = [pos1]
for pos in bbox:
block = brushLoc.POS['world': pos]
for block_type in types:
try:
allowed = brushLoc.BLOCK_LOOKUP[block_type.casefold()]
except KeyError:
raise ValueError('"{}" is not a valid block type!'.format(block_type))
if block in allowed:
break # To next position
else:
return False # Didn't match any in this list.
return True # Matched all positions.
示例4: add_glass_floorbeams
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
def add_glass_floorbeams(vmf: VMF, temp_name: str):
"""Add beams to separate large glass panels.
The texture is assumed to match plasticwall004a's shape.
"""
template = template_brush.get_template(temp_name)
temp_world, temp_detail, temp_over = template.visgrouped()
try:
[beam_template] = temp_world + temp_detail # type: Solid
except ValueError:
raise ValueError('Bad Glass Floorbeam template!')
# Grab the 'end' side, which we move around.
for side in beam_template.sides:
if side.normal() == (-1, 0, 0):
beam_end_face = side
break
else:
raise ValueError('Not aligned to world...')
separation = vbsp_options.get(int, 'glass_floorbeam_sep') + 1
separation *= 128
# First we want to find all the groups of contiguous glass sections.
# This is a mapping from some glass piece to its group list.
groups = {}
for (origin, normal), barr_type in BARRIERS.items():
# Grating doesn't use it.
if barr_type is not BarrierType.GLASS:
continue
normal = Vec(normal)
if not normal.z:
# Not walls.
continue
pos = Vec(origin) + normal * 62
groups[pos.as_tuple()] = [pos]
# Loop over every pos and check in the +x/y directions for another glass
# piece. If there, merge the two lists and set every pos in the group to
# point to the new list.
# Once done, every unique list = a group.
for pos_tup in groups.keys():
pos = Vec(pos_tup)
for off in ((128, 0, 0), (0, 128, 0)):
neighbour = (pos + off).as_tuple()
if neighbour in groups:
our_group = groups[pos_tup]
neigh_group = groups[neighbour]
if our_group is neigh_group:
continue
# Now merge the two lists. We then need to update all dict locs
# to point to the new list.
if len(neigh_group) > len(our_group):
small_group, large_group = our_group, neigh_group
else:
small_group, large_group = neigh_group, our_group
large_group.extend(small_group)
for pos in small_group:
groups[pos.as_tuple()] = large_group
# Remove duplicates objects by using the ID as key..
groups = list({
id(group): group
for group in groups.values()
}.values())
# Side -> u, v or None
for group in groups:
bbox_min, bbox_max = Vec.bbox(group)
dimensions = bbox_max - bbox_min
LOGGER.info('Size = {}', dimensions)
# Our beams align to the smallest axis.
if dimensions.y > dimensions.x:
beam_ax = 'x'
side_ax = 'y'
rot = Vec(0, 0, 0)
else:
beam_ax = 'y'
side_ax = 'x'
rot = Vec(0, 90, 0)
# Build min, max tuples for each axis in the other direction.
# This tells us where the beams will be.
beams = {} # type: Dict[int, Tuple[int, int]]
# Add 128 so the first pos isn't a beam.
offset = bbox_min[side_ax] + 128
#.........这里部分代码省略.........
示例5: res_resizeable_trigger
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
#.........这里部分代码省略.........
# We do while + pop to allow removing both names each loop through.
todo_names = set(marker_names)
while todo_names:
targ = todo_names.pop()
mark1 = connections.ITEMS.pop(targ)
for conn in mark1.outputs:
if conn.to_item.name in marker_names:
mark2 = conn.to_item
conn.remove() # Delete this connection.
todo_names.discard(mark2.name)
del connections.ITEMS[mark2.name]
break
else:
if not mark1.inputs:
# If the item doesn't have any connections, 'connect'
# it to itself so we'll generate a 1-block trigger.
mark2 = mark1
else:
# It's a marker with an input, the other in the pair
# will handle everything.
# But reinstate it in ITEMS.
connections.ITEMS[targ] = mark1
continue
inst1 = mark1.inst
inst2 = mark2.inst
is_coop = coop_var is not None and vbsp.GAME_MODE == 'COOP' and (
inst1.fixup.bool(coop_var) or
inst2.fixup.bool(coop_var)
)
bbox_min, bbox_max = Vec.bbox(
Vec.from_str(inst1['origin']),
Vec.from_str(inst2['origin'])
)
origin = (bbox_max + bbox_min) / 2
# Extend to the edge of the blocks.
bbox_min -= 64
bbox_max += 64
out_ent = trig_ent = vmf.create_ent(
classname='trigger_multiple', # Default
targetname=targ,
origin=origin,
angles='0 0 0',
)
trig_ent.solids = [
vmf.make_prism(
bbox_min,
bbox_max,
mat=const.Tools.TRIGGER,
).solid,
]
# Use 'keys' and 'localkeys' blocks to set all the other keyvalues.
conditions.set_ent_keys(trig_ent, inst, res)
if is_coop:
trig_ent['spawnflags'] = '1' # Clients
trig_ent['classname'] = 'trigger_playerteam'
out_ent = manager = vmf.create_ent(
classname='logic_coop_manager',
示例6: parse_map
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import bbox [as 别名]
def parse_map(vmf: VMF, voice_attrs: Dict[str, bool]) -> None:
"""Analyse fizzler instances to assign fizzler types.
Instance traits are required.
The model instances and brushes will be removed from the map.
Needs connections to be parsed.
"""
# Item ID and model skin -> fizzler type
fizz_types = {} # type: Dict[Tuple[str, int], FizzlerType]
for fizz_type in FIZZ_TYPES.values():
for item_id in fizz_type.item_ids:
if ':' in item_id:
item_id, barrier_type = item_id.split(':')
if barrier_type == 'laserfield':
barrier_skin = 2
elif barrier_type == 'fizzler':
barrier_skin = 0
else:
LOGGER.error('Invalid barrier type ({}) for "{}"!', barrier_type, item_id)
fizz_types[item_id, 0] = fizz_type
fizz_types[item_id, 2] = fizz_type
continue
fizz_types[item_id, barrier_skin] = fizz_type
else:
fizz_types[item_id, 0] = fizz_type
fizz_types[item_id, 2] = fizz_type
fizz_bases = {} # type: Dict[str, Entity]
fizz_models = defaultdict(list) # type: Dict[str, List[Entity]]
# Position and normal -> name, for output relays.
fizz_pos = {} # type: Dict[Tuple[Tuple[float, float, float], Tuple[float, float, float]], str]
# First use traits to gather up all the instances.
for inst in vmf.by_class['func_instance']:
traits = instance_traits.get(inst)
if 'fizzler' not in traits:
continue
name = inst['targetname']
if 'fizzler_model' in traits:
name = name.rsplit('_model', 1)[0]
fizz_models[name].append(inst)
inst.remove()
elif 'fizzler_base' in traits:
fizz_bases[name] = inst
else:
LOGGER.warning('Fizzler "{}" has non-base, non-model instance?', name)
continue
origin = Vec.from_str(inst['origin'])
normal = Vec(z=1).rotate_by_str(inst['angles'])
fizz_pos[origin.as_tuple(), normal.as_tuple()] = name
for name, base_inst in fizz_bases.items():
models = fizz_models[name]
up_axis = Vec(y=1).rotate_by_str(base_inst['angles'])
# If upside-down, make it face upright.
if up_axis == (0, 0, -1):
up_axis = Vec(z=1)
base_inst.outputs.clear()
# Now match the pairs of models to each other.
# The length axis is the line between them.
# We don't care about the instances after this, so don't keep track.
length_axis = Vec(z=1).rotate_by_str(base_inst['angles']).axis()
emitters = [] # type: List[Tuple[Vec, Vec]]
model_pairs = {} # type: Dict[Tuple[float, float], Vec]
model_skin = models[0].fixup.int('$skin')
try:
item_id, item_subtype = instanceLocs.ITEM_FOR_FILE[base_inst['file'].casefold()]
fizz_type = fizz_types[item_id, model_skin]
except KeyError:
LOGGER.warning('Fizzler types: {}', fizz_types.keys())
raise ValueError('No fizzler type for "{}"!'.format(
base_inst['file'],
)) from None
for attr_name in fizz_type.voice_attrs:
voice_attrs[attr_name] = True
for model in models:
pos = Vec.from_str(model['origin'])
try:
other_pos = model_pairs.pop(pos.other_axes(length_axis))
except KeyError:
# No other position yet, we need to find that.
model_pairs[pos.other_axes(length_axis)] = pos
continue
min_pos, max_pos = Vec.bbox(pos, other_pos)
#.........这里部分代码省略.........