Exemple #1
0
def export_meshbv(b_obj, hitcheck, corrector):
	me = b_obj.data
	matrix = get_collider_matrix(b_obj)

	hitcheck.type = CollisionType.MeshCollision
	hitcheck.collider = MeshCollision()
	coll = hitcheck.collider

	bounds_max, bounds_min = get_bounds((b_obj.bound_box, ))
	assign_bounds(coll, bounds_max, bounds_min)

	# export rotation
	set_rot_matrix(matrix, hitcheck.collider.rotation, corrector)
	# export translation
	c = coll.offset
	c.x, c.y, c.z = pack_swizzle(matrix.translation)
	# export vertices
	coll.vertex_count = len(me.vertices)
	coll.vertices.resize((coll.vertex_count, 3))
	for vert_i, vert in enumerate(me.vertices):
		coll.vertices[vert_i, :] = pack_swizzle(vert.co)
	# export triangles
	coll.tri_count = len(me.polygons)
	coll.triangles.resize((coll.tri_count, 3))
	for face_i, face in enumerate(me.polygons):
		coll.triangles[face_i, :] = face.vertices
		assert len(face.vertices) == 3
Exemple #2
0
def export_boxbv(b_obj, hitcheck, corrector):
	hitcheck.type = CollisionType.BoundingBox
	hitcheck.collider = BoundingBox()

	matrix = get_collider_matrix(b_obj)
	c = hitcheck.collider.center
	c.x, c.y, c.z = pack_swizzle(matrix.translation)
	e = hitcheck.collider.extent
	dim = b_obj.dimensions
	e.x, e.y, e.z = pack_swizzle((dim.y, dim.x, dim.z))
	set_rot_matrix(matrix, hitcheck.collider.rotation, corrector)
Exemple #3
0
def _capsule_transform(b_obj, hitcheck):
	matrix = get_collider_matrix(b_obj)
	offset = matrix.translation
	# calculate the direction unit vector
	v_dir = (mathutils.Vector((0, 0, 1)) @ matrix.to_3x3().inverted()).normalized()

	c = hitcheck.collider.offset
	c.x, c.y, c.z = pack_swizzle(offset)

	d = hitcheck.collider.direction
	d.x, d.y, d.z = pack_swizzle(v_dir)

	hitcheck.collider.extent = b_obj.dimensions.z - b_obj.dimensions.x
	hitcheck.collider.radius = b_obj.dimensions.x / 2
Exemple #4
0
def export_spherebv(b_obj, hitcheck):
	hitcheck.type = CollisionType.Sphere
	hitcheck.collider = Sphere()

	matrix = get_collider_matrix(b_obj)
	hitcheck.collider.radius = b_obj.dimensions.x / 2
	c = hitcheck.collider.center
	c.x, c.y, c.z = pack_swizzle(matrix.translation)
Exemple #5
0
def get_bounds(bounds):
	bounds_max = mathutils.Vector((-v, -v, -v))
	bounds_min = mathutils.Vector((v, v, v))
	for bound in bounds:
		for co in bound:
			for i in range(3):
				vec = pack_swizzle(co)
				bounds_min[i] = min(bounds_min[i], vec[i])
				bounds_max[i] = max(bounds_max[i], vec[i])
	return bounds_max, bounds_min
Exemple #6
0
def export_hullbv(b_obj, hitcheck, corrector):
	me = b_obj.data
	matrix = get_collider_matrix(b_obj)

	hitcheck.type = CollisionType.ConvexHull
	hitcheck.collider = ConvexHull()
	coll = hitcheck.collider

	# export rotation
	set_rot_matrix(matrix, hitcheck.collider.rotation, corrector)
	# export translation
	c = coll.offset
	c.x, c.y, c.z = pack_swizzle(matrix.translation)
	# export vertices
	coll.vertex_count = len(me.vertices)
	coll.vertices = np.empty((coll.vertex_count, 3), dtype="float")
	# coll.vertices.resize((coll.vertex_count, 3))
	for vert_i, vert in enumerate(me.vertices):
		coll.vertices[vert_i, :] = pack_swizzle2(vert.co)