本文整理汇总了Python中mathutils.Vector.xyz方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.xyz方法的具体用法?Python Vector.xyz怎么用?Python Vector.xyz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.xyz方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def draw(self, scene=bpy.context.scene, maxdensity=None, matrix_world=None):
""" draws the reflection plane in the scene """
base = self.rnor * self.roff
#rme = bpy.data.meshes.new('rNormal')
#normalverts = [base, base + self.rnor]
#normaledge = [[0, 1]]
#rme.from_pydata(normalverts,normaledge,[])
#ob_normal = bpy.data.objects.new("rNormal", rme)
#scene.objects.link(ob_normal)
n = Vector() # self rotation in (phi,theta,0)
n.xyz = (-self.co.x,
-self.co.y,
0)
mesh = bpy.ops.mesh.primitive_plane_add(
radius=2,
location = base,
rotation=n.zyx)
obj = bpy.context.active_object
obj.hide = True
if matrix_world:
obj.matrix_world = matrix_world * obj.matrix_world
if maxdensity:
material = bpy.data.materials.new('color')
material.diffuse_color = (self.weight/maxdensity,
1 - self.weight/maxdensity,
1 - self.weight/maxdensity)
mesh = obj.data
mesh.materials.append(material)
示例2: calculate_tangent_space
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def calculate_tangent_space(vertex, uv_layer):
vertex_tangent = Vector((0.0, 0.0, 0.0, 0.0))
vertex_bitangent = Vector((0.0, 0.0, 0.0, 0.0))
# Accumulate faceted tangents
for i in range(len(vertex.link_faces)):
face = vertex.link_faces[i]
position0 = face.loops[0].vert.co
position1 = face.loops[1].vert.co
position2 = face.loops[2].vert.co
uv0 = face.loops[0][uv_layer].uv
uv1 = face.loops[1][uv_layer].uv
uv2 = face.loops[2][uv_layer].uv
position_edge1 = position1 - position0
position_edge2 = position2 - position0
uv_edge1 = uv1 - uv0
uv_edge2 = uv2 - uv0
inverseDet = uv_edge1.x * uv_edge2.y - uv_edge1.y * uv_edge2.x
if inverseDet != 0.0:
inverseDet = 1.0 / inverseDet
vertex_tangent.xyz += (position_edge1 * uv_edge2.y - position_edge2 * uv_edge1.y) * inverseDet
vertex_bitangent.xyz += (position_edge2 * uv_edge1.x - position_edge1 * uv_edge2.x) * inverseDet
# Gram-Schmidt orthogonalize
n = vertex.normal
t = vertex_tangent.xyz.copy()
b = vertex_bitangent.xyz.copy()
n_dot_t = n.dot(t)
vertex_tangent.xyz = (t - n * n_dot_t).normalized()
vertex_bitangent.xyz = (b - n * n_dot_t).normalized()
handedness = -1.0 if (n.cross(t).dot(b) < 0.0) else 1.0
vertex_tangent.w = handedness
vertex_bitangent.w = handedness
return (vertex_tangent, vertex_bitangent)
示例3: scan_advanced
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def scan_advanced(scanner_object, max_distance = 10.0, evd_file=None, add_blender_mesh = False,
add_noisy_blender_mesh = False, tof_res_x = 176, tof_res_y = 144,
lens_angle_w=43.6, lens_angle_h=34.6, flength = 10.0, evd_last_scan=True,
noise_mu=0.0, noise_sigma=0.004, timestamp = 0.0, backfolding=False,
world_transformation=Matrix()):
inv_scan_x = scanner_object.inv_scan_x
inv_scan_y = scanner_object.inv_scan_y
inv_scan_z = scanner_object.inv_scan_z
start_time = time.time()
#10.0mm is currently the distance between the focal point and the sensor
sensor_width = 2 * math.tan(deg2rad(lens_angle_w/2.0)) * 10.0
sensor_height = 2 * math.tan(deg2rad(lens_angle_h/2.0)) * 10.0
if tof_res_x == 0 or tof_res_y == 0:
raise ValueError("Resolution must be > 0")
pixel_width = sensor_width / float(tof_res_x)
pixel_height = sensor_height / float(tof_res_y)
bpy.context.scene.render.resolution_percentage
width = bpy.context.scene.render.resolution_x
height = bpy.context.scene.render.resolution_y
cx = float(tof_res_x) /2.0
cy = float(tof_res_y) /2.0
evd_buffer = []
rays = []
ray_info = []
ray = Vector([0.0,0.0,0.0])
for x in range(tof_res_x):
for y in range(tof_res_y):
"""Calculate a vector that originates at the principal point
and points to the pixel in the sensor. This vector is then
scaled to the maximum scanning distance
"""
physical_x = float(x-cx) * pixel_width
physical_y = float(y-cy) * pixel_height
physical_z = -float(flength)
ray.xyz = [physical_x, physical_y, physical_z]
ray.normalize()
final_ray = max_distance*ray
rays.extend([final_ray[0],final_ray[1],final_ray[2]])
""" pitch and yaw are added for completeness, normally they are
not provided by a ToF Camera but can be derived
from the pixel position and the camera parameters.
"""
yaw = math.atan(physical_x/flength)
pitch = math.atan(physical_y/flength)
ray_info.append([yaw, pitch, timestamp])
returns = blensor.scan_interface.scan_rays(rays, max_distance, inv_scan_x = inv_scan_x, inv_scan_y = inv_scan_y, inv_scan_z = inv_scan_z)
verts = []
verts_noise = []
evd_storage = evd.evd_file(evd_file, tof_res_x, tof_res_y, max_distance)
reusable_vector = Vector([0.0,0.0,0.0,0.0])
for i in range(len(returns)):
idx = returns[i][-1]
distance_noise = random.gauss(noise_mu, noise_sigma)
#If everything works substitute the previous line with this
#distance_noise = pixel_noise[returns[idx][-1]] + random.gauss(noise_mu, noise_sigma)
reusable_vector.xyzw = [returns[i][1],returns[i][2],returns[i][3],1.0]
vt = (world_transformation * reusable_vector).xyz
v = [returns[i][1],returns[i][2],returns[i][3]]
verts.append ( vt )
vector_length = math.sqrt(v[0]**2+v[1]**2+v[2]**2)
norm_vector = [v[0]/vector_length, v[1]/vector_length, v[2]/vector_length]
vector_length_noise = vector_length+distance_noise
if backfolding:
#Distances > max_distance/2..max_distance are mapped to 0..max_distance/2
if vector_length_noise >= max_distance/2.0:
vector_length_noise = vector_length_noise - max_distance/2.0
reusable_vector.xyzw = [norm_vector[0]*vector_length_noise, norm_vector[1]*vector_length_noise, norm_vector[2]*vector_length_noise,1.0]
v_noise = (world_transformation * reusable_vector).xyz
verts_noise.append( v_noise )
evd_storage.addEntry(timestamp = ray_info[idx][2], yaw =(ray_info[idx][0]+math.pi)%(2*math.pi), pitch=ray_info[idx][1], distance=vector_length, distance_noise=vector_length_noise, x=vt[0], y=vt[1], z=vt[2], x_noise=v_noise[0], y_noise=v_noise[1], z_noise=v_noise[2], object_id=returns[i][4], color=returns[i][5], idx=returns[i][-1])
if evd_file:
evd_storage.appendEvdFile()
#.........这里部分代码省略.........
示例4: scan_advanced
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def scan_advanced(scanner_object, evd_file=None,
evd_last_scan=True,
timestamp = 0.0,
world_transformation=Matrix()):
# threshold for comparing projector and camera rays
thresh = 0.01
inv_scan_x = scanner_object.inv_scan_x
inv_scan_y = scanner_object.inv_scan_y
inv_scan_z = scanner_object.inv_scan_z
x_multiplier = -1.0 if inv_scan_x else 1.0
y_multiplier = -1.0 if inv_scan_y else 1.0
z_multiplier = -1.0 if inv_scan_z else 1.0
start_time = time.time()
max_distance = scanner_object.kinect_max_dist
min_distance = scanner_object.kinect_min_dist
add_blender_mesh = scanner_object.add_scan_mesh
add_noisy_blender_mesh = scanner_object.add_noise_scan_mesh
noise_mu = scanner_object.kinect_noise_mu
noise_sigma = scanner_object.kinect_noise_sigma
noise_scale = scanner_object.kinect_noise_scale
noise_smooth = scanner_object.kinect_noise_smooth
res_x = scanner_object.kinect_xres
res_y = scanner_object.kinect_yres
flength = scanner_object.kinect_flength
WINDOW_INLIER_DISTANCE = scanner_object.kinect_inlier_distance
if res_x < 1 or res_y < 1:
raise ValueError("Resolution must be > 0")
pixel_width = 0.0078
pixel_height = 0.0078
cx = float(res_x) /2.0
cy = float(res_y) /2.0
evd_buffer = []
rays = [0.0]*res_y*res_x*6
ray_info = [[0.0,0.0,0.0]]*res_y*res_x
baseline = Vector([0.075,0.0,0.0]) #Kinect has a baseline of 7.5 centimeters
rayidx=0
ray = Vector([0.0,0.0,0.0])
"""Calculate the rays from the projector"""
for y in range(res_y):
for x in range(res_x):
"""Calculate a vector that originates at the principal point
and points to the pixel in the sensor. This vector is then
scaled to the maximum scanning distance
"""
physical_x = float(x-cx) * pixel_width
physical_y = float(y-cy) * pixel_height
physical_z = -float(flength)
#ray = Vector([physical_x, physical_y, physical_z])
ray.xyz=[physical_x, physical_y, physical_z]
ray.normalize()
final_ray = max_distance*ray
rays[rayidx*6] = final_ray[0]
rays[rayidx*6+1] = final_ray[1]
rays[rayidx*6+2] = final_ray[2]
rays[rayidx*6+3] = baseline.x
rays[rayidx*6+4] = baseline.y
rays[rayidx*6+5] = baseline.z
""" pitch and yaw are added for completeness, normally they are
not provided by a ToF Camera but can be derived
from the pixel position and the camera parameters.
"""
yaw = math.atan(physical_x/flength)
pitch = math.atan(physical_y/flength)
ray_info[rayidx][0] = yaw
ray_info[rayidx][1] = pitch
ray_info[rayidx][2] = timestamp
rayidx += 1
""" Max distance is increased because the kinect is limited by 4m
_normal distance_ to the imaging plane, We don't need shading in the
first pass.
#TODO: the shading requirements might change when transmission
is implemented (the rays might pass through glass)
"""
returns = blensor.scan_interface.scan_rays(rays, 2.0*max_distance, True,True,True,True)
camera_rays = []
projector_ray_index = -1 * numpy.ones(len(returns), dtype=numpy.uint32)
kinect_image = numpy.zeros((res_x*res_y,16))
#.........这里部分代码省略.........
示例5: scan_advanced
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def scan_advanced(scanner_object, rotation_speed = 10.0, simulation_fps=24, angle_resolution = 0.1728, max_distance = 120, evd_file=None,noise_mu=0.0, noise_sigma=0.03, start_angle = 0.0, end_angle = 360.0, evd_last_scan=True, add_blender_mesh = False, add_noisy_blender_mesh = False, frame_time = (1.0 / 24.0), simulation_time = 0.0, world_transformation=Matrix()):
start_time = time.time()
current_time = simulation_time
delta_rot = angle_resolution*math.pi/180
evd_storage = evd.evd_file(evd_file)
xaxis = Vector([1,0,0])
yaxis = Vector([0,1,0])
zaxis = Vector([0,0,1])
rays = []
ray_info = []
steps_per_rotation = 360.0/angle_resolution
time_per_step = (1.0 / rotation_speed) / steps_per_rotation
angles = end_angle-start_angle
lines = (end_angle-start_angle)/angle_resolution
ray = Vector([0.0,0.0,0.0])
for line in range(int(lines)):
for laser_idx in range(len(laser_angles)):
ray.xyz = [0,0,max_distance]
rot_angle = 1e-6 + start_angle+float(line)*angle_resolution + 180.0
timestamp = ( (rot_angle-180.0)/angle_resolution) * time_per_step
rot_angle = rot_angle%360.0
ray_info.append([deg2rad(rot_angle), deg2rad(laser_angles[laser_idx]), timestamp])
rotator = Euler( [deg2rad(-laser_angles[laser_idx]), deg2rad(rot_angle), 0.0] )
ray.rotate( rotator )
rays.extend([ray[0],ray[1],ray[2]])
returns = blensor.scan_interface.scan_rays(rays, max_distance)
verts = []
verts_noise = []
# for idx in range((len(rays)//3)):
reusable_4dvector = Vector([0.0,0.0,0.0,0.0])
for i in range(len(returns)):
idx = returns[i][-1]
reusable_4dvector.xyzw = (returns[i][1],returns[i][2],returns[i][3],1.0)
vt = (world_transformation * reusable_4dvector).xyz
v = [returns[i][1],returns[i][2],returns[i][3]]
verts.append ( vt )
distance_noise = laser_noise[idx%len(laser_noise)] + random.gauss(noise_mu, noise_sigma)
vector_length = math.sqrt(v[0]**2+v[1]**2+v[2]**2)
norm_vector = [v[0]/vector_length, v[1]/vector_length, v[2]/vector_length]
vector_length_noise = vector_length+distance_noise
reusable_4dvector.xyzw=[norm_vector[0]*vector_length_noise, norm_vector[1]*vector_length_noise, norm_vector[2]*vector_length_noise,1.0]
v_noise = (world_transformation * reusable_4dvector).xyz
verts_noise.append( v_noise )
evd_storage.addEntry(timestamp = ray_info[idx][2], yaw =(ray_info[idx][0]+math.pi)%(2*math.pi), pitch=ray_info[idx][1], distance=vector_length, distance_noise=vector_length_noise, x=vt[0], y=vt[1], z=vt[2], x_noise=v_noise[0], y_noise=v_noise[1], z_noise=v_noise[2], object_id=returns[i][4], color=returns[i][5])
current_angle = start_angle+float(float(int(lines))*angle_resolution)
pre_write_time = time.time()
if evd_file:
evd_storage.appendEvdFile()
if add_blender_mesh:
mesh_utils.add_mesh_from_points_tf(verts, "Scan", world_transformation)
if add_noisy_blender_mesh:
mesh_utils.add_mesh_from_points_tf(verts_noise, "NoisyScan", world_transformation)
bpy.context.scene.update()
end_time = time.time()
scan_time = pre_write_time-start_time
total_time = end_time-start_time
print ("Elapsed time: %.3f (scan: %.3f)"%(total_time, scan_time))
return True, current_angle, scan_time
示例6: scan_advanced
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import xyz [as 别名]
def scan_advanced(scanner_object, simulation_fps=24, evd_file=None,noise_mu=0.0, evd_last_scan=True, add_blender_mesh = False, add_noisy_blender_mesh = False, simulation_time = 0.0,laser_mirror_distance=0.05, world_transformation=Matrix()):
angle_resolution=scanner_object.generic_angle_resolution
max_distance=scanner_object.generic_max_dist
start_angle=scanner_object.generic_start_angle
end_angle=scanner_object.generic_end_angle
noise_mu = scanner_object.generic_noise_mu
noise_sigma=scanner_object.generic_noise_sigma
laser_angles = scanner_object.generic_laser_angles
rotation_speed = scanner_object.generic_rotation_speed
inv_scan_x = scanner_object.inv_scan_x
inv_scan_y = scanner_object.inv_scan_y
inv_scan_z = scanner_object.inv_scan_z
"""Standard Error model is a Gaussian Distribution"""
model = gaussian_error_model.GaussianErrorModel(noise_mu, noise_sigma)
if scanner_object.generic_advanced_error_model:
"""Advanced error model is a list of distance,mu,sigma tuples"""
model = advanced_error_model.AdvancedErrorModel(scanner_object.generic_advanced_error_model)
start_time = time.time()
current_time = simulation_time
delta_rot = angle_resolution*math.pi/180
evd_storage = evd.evd_file(evd_file)
xaxis = Vector([1,0,0])
yaxis = Vector([0,1,0])
zaxis = Vector([0,0,1])
rays = []
ray_info = []
angles = end_angle-start_angle
steps_per_rotation = angles/angle_resolution
time_per_step = (1.0/rotation_speed) / steps_per_rotation
lines = (end_angle-start_angle)/angle_resolution
laser_angles = angles_from_string(laser_angles)
rays = []
ray_info = []
#Bad code???
#steps_per_rotation = 360.0/angle_resolution
#time_per_step = (1.0 / rotation_speed) / steps_per_rotation
#angles = end_angle-start_angle
lines = (end_angle-start_angle)/angle_resolution
ray = Vector([0.0,0.0,0.0])
for line in range(int(lines)):
for laser_idx in range(len(laser_angles)):
ray.xyz = [0,0,max_distance]
rot_angle = 1e-6 + start_angle+float(line)*angle_resolution + 180.0
timestamp = ( (rot_angle-180.0)/angle_resolution) * time_per_step
rot_angle = rot_angle%360.0
ray_info.append([deg2rad(rot_angle), deg2rad(laser_angles[laser_idx]), timestamp])
rotator = Euler( [deg2rad(-laser_angles[laser_idx]), deg2rad(rot_angle), 0.0] )
ray.rotate( rotator )
rays.extend([ray[0],ray[1],ray[2]])
returns = blensor.scan_interface.scan_rays(rays, max_distance, inv_scan_x = inv_scan_x, inv_scan_y = inv_scan_y, inv_scan_z = inv_scan_z)
verts = []
verts_noise = []
reusable_vector = Vector([0.0,0.0,0.0,0.0])
if len(laser_angles) != len(laser_noise):
randomize_distance_bias(len(laser_angles), noise_mu,noise_sigma)
for i in range(len(returns)):
idx = returns[i][-1]
reusable_vector.xyzw = [returns[i][1],returns[i][2],returns[i][3],1.0]
vt = (world_transformation * reusable_vector).xyz
v = [returns[i][1],returns[i][2],returns[i][3]]
verts.append ( vt )
vector_length = math.sqrt(v[0]**2+v[1]**2+v[2]**2)
distance_noise = laser_noise[idx%len(laser_noise)] + model.drawErrorFromModel(vector_length)
norm_vector = [v[0]/vector_length, v[1]/vector_length, v[2]/vector_length]
vector_length_noise = vector_length+distance_noise
reusable_vector.xyzw = [norm_vector[0]*vector_length_noise, norm_vector[1]*vector_length_noise, norm_vector[2]*vector_length_noise,1.0]
v_noise = (world_transformation * reusable_vector).xyz
verts_noise.append( v_noise )
evd_storage.addEntry(timestamp = ray_info[idx][2], yaw =(ray_info[idx][0]+math.pi)%(2*math.pi), pitch=ray_info[idx][1], distance=vector_length, distance_noise=vector_length_noise, x=vt[0], y=vt[1], z=vt[2], x_noise=v_noise[0], y_noise=v_noise[1], z_noise=v_noise[2], object_id=returns[i][4], color=returns[i][5])
current_angle = start_angle+float(float(int(lines))*angle_resolution)
if evd_file:
evd_storage.appendEvdFile()
#.........这里部分代码省略.........