def run(self):
domeLocation = self.getInputValue("Dome Location")
domeRadius = self.getInputValue("Dome Radius")
rayLocation = self.getInputValue("Location")
rayRotation = self.getInputValue("Rotation")
rayVector = Vector((0.0, 1.0, 0.0))
rayVector.rotate(rayRotation)
# Intersect ray with dome
rayDomeVec = rayLocation - domeLocation
a = rayVector.dot(rayVector)
b = 2 * rayVector.dot(rayDomeVec)
c = rayDomeVec.dot(rayDomeVec) - (domeRadius * domeRadius)
result, t0, t1 = self.solveQuadratic(a, b, c)
if not result:
return self.nothing(True)
if t0 < 0:
# if t0 is negative, let's use t1 instead
t0 = t1
if t0 < 0:
# both t0 and t1 are negative
return self.nothing(True)
# Find intersection point with dome
rayVector.length = t0
domeRayLocation = rayLocation + rayVector
self.outputs["Dome Intersection"].default_value = domeRayLocation
# Find vector/rotation pointing from dome center to that intersection point
domeLoc = domeRayLocation.normalized()
dirVector = Vector((0.0, 1.0, 0.0))
axis = dirVector.cross(domeLoc)
angle = math.acos(dirVector.dot(domeLoc))
rayRotation = Quaternion(axis, angle)
self.outputs["Ray Orientation"].default_value = rayRotation
rayVector = Vector((0.0, 1.0, 0.0))
rayVector.rotate(rayRotation)
result, location, normal, index, object, matrix = bpy.context.scene.ray_cast(domeLocation, rayVector)
if not result:
return self.nothing(False)
self.outputs["Result"].default_value = result
self.outputs["Object"].default_value = object.name
self.outputs["Location"].default_value = location
self.outputs["Normal"].default_value = normal
DomeRayCastNode.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录