5
5
6
6
machineEpsilon = np .finfo (float ).eps
7
7
8
+
9
+ # Calculate the minimum reflectivty that will cause a laser return
10
+ def blensor_calculate_reflectivity_limit (dist ,
11
+ reflectivity_distance ,
12
+ reflectivity_limit ,
13
+ reflectivity_slope ):
14
+ min_reflectivity = - 1.0
15
+ if dist >= reflectivity_distance :
16
+ min_reflectivity = reflectivity_limit + reflectivity_slope * (dist - reflectivity_distance )
17
+
18
+ return min_reflectivity
19
+
20
+
8
21
"""Raycast scene with individual rays
9
22
Return per hit:
10
23
distance,
@@ -38,6 +51,9 @@ def scan(numberOfRays, max_distance, elementsPerRay, keep_render_setup, do_shadi
38
51
39
52
# Step 3: Raycast rays
40
53
scanner = bpy .context .scene .camera
54
+ reflectivity_distance = scanner .ref_dist
55
+ reflectivity_limit = scanner .ref_limit
56
+ reflectivity_slope = scanner .ref_slope
41
57
42
58
origin = Vector ([0.0 ,0.0 ,0.0 ])
43
59
direction = Vector ([0.0 ,0.0 ,0.0 ])
@@ -62,23 +78,41 @@ def scan(numberOfRays, max_distance, elementsPerRay, keep_render_setup, do_shadi
62
78
63
79
(hit_loc , hit_normal , hit_idx , hit_distance ) = scene_bvh .ray_cast (origin ,direction ,max_distance )
64
80
81
+ valid_return = False
65
82
if hit_loc :
66
- returns_buffer [idx * ELEMENTS_PER_RETURN ] = hit_distance
67
- returns_buffer [idx * ELEMENTS_PER_RETURN + 1 ] = hit_loc .x
68
- returns_buffer [idx * ELEMENTS_PER_RETURN + 2 ] = hit_loc .y
69
- returns_buffer [idx * ELEMENTS_PER_RETURN + 3 ] = hit_loc .z
70
-
71
- obj = obj_array [hit_idx ]
72
- name = obj .name
73
- returns_buffer [idx * ELEMENTS_PER_RETURN + 4 ] = ord (name [0 ]) + (ord (name [1 ])<< 8 ) + (ord (name [2 ])<< 16 ) + (ord (name [3 ])<< 24 )
74
-
75
- returns_buffer [idx * ELEMENTS_PER_RETURN + 5 ] = 1.0
76
- returns_buffer [idx * ELEMENTS_PER_RETURN + 6 ] = 1.0
77
- returns_buffer [idx * ELEMENTS_PER_RETURN + 7 ] = 1.0
78
-
79
- hit_indices [idx ] = hit_idx
80
-
81
- else :
83
+ mat = mat_array [hit_idx ]
84
+
85
+ diffuse_intensity = 1.0
86
+ if mat :
87
+ diffuse_intensity = mat .diffuse_intensity
88
+
89
+ #Calculate the required diffuse reflectivity of the material to create a return
90
+ ref_limit = blensor_calculate_reflectivity_limit (hit_distance , reflectivity_distance , reflectivity_limit , reflectivity_slope )
91
+
92
+ if diffuse_intensity > ref_limit :
93
+ valid_return = True
94
+ if mat :
95
+ color = mat .diffuse_color
96
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 5 ] = color .r
97
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 6 ] = color .g
98
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 7 ] = color .b
99
+ else :
100
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 5 ] = 1.0
101
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 6 ] = 1.0
102
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 7 ] = 1.0
103
+
104
+ returns_buffer [idx * ELEMENTS_PER_RETURN ] = hit_distance
105
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 1 ] = hit_loc .x
106
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 2 ] = hit_loc .y
107
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 3 ] = hit_loc .z
108
+
109
+ obj = obj_array [hit_idx ]
110
+ name = obj .name
111
+ returns_buffer [idx * ELEMENTS_PER_RETURN + 4 ] = ord (name [0 ]) + (ord (name [1 ])<< 8 ) + (ord (name [2 ])<< 16 ) + (ord (name [3 ])<< 24 )
112
+
113
+ hit_indices [idx ] = hit_idx
114
+
115
+ if not valid_return :
82
116
for r in range (ELEMENTS_PER_RETURN ):
83
117
returns_buffer [idx * ELEMENTS_PER_RETURN + r ] = 0.0
84
118
@@ -87,12 +121,8 @@ def scan(numberOfRays, max_distance, elementsPerRay, keep_render_setup, do_shadi
87
121
if do_shading :
88
122
for idx ,mat_idx in enumerate (hit_indices ):
89
123
if mat_idx >= 0 :
90
- color = mat_array [mat_idx ].diffuse_color
91
- returns_buffer [idx * ELEMENTS_PER_RETURN + 5 ] = color .r
92
- returns_buffer [idx * ELEMENTS_PER_RETURN + 6 ] = color .g
93
- returns_buffer [idx * ELEMENTS_PER_RETURN + 7 ] = color .b
94
-
95
-
124
+ #shade hit point
125
+ pass
96
126
97
127
98
128
def scene_to_mesh ():
0 commit comments