Example #1
0
    def evaluate_array(self, us, vs):
        c1_min, c1_max = self.curve1.get_u_bounds()
        c2_min, c2_max = self.curve2.get_u_bounds()
        c1_us = (c1_max - c1_min) * us + c1_min
        c2_us = (c2_max - c2_min) * us + c2_min

        _, c1_points, _, _, c1_binormals = curve_frame_on_surface_array(self.surface1, self.curve1, c1_us)
        _, c2_points, _, _, c2_binormals = curve_frame_on_surface_array(self.surface2, self.curve2, c2_us)
        c1_binormals = self.bulge1 * c1_binormals
        c2_binormals = self.bulge2 * c2_binormals

        # See also sverchok.utils.curve.bezier.SvCubicBezierCurve.
        # Here we have re-implementation of the same algorithm
        # which works with arrays of control points
        p0s = c1_points                 # (n, 3)
        p1s = c1_points + c1_binormals
        p2s = c2_points + c2_binormals
        p3s = c2_points

        c0 = (1 - vs)**3      # (n,)
        c1 = 3*vs*(1-vs)**2
        c2 = 3*vs**2*(1-vs)
        c3 = vs**3

        # (n,1)
        c0, c1, c2, c3 = c0[:,np.newaxis], c1[:,np.newaxis], c2[:,np.newaxis], c3[:,np.newaxis]

        return c0*p0s + c1*p1s + c2*p2s + c3*p3s
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        surface_s = self.inputs['Surface'].sv_get()
        curve_s = self.inputs['UVCurve'].sv_get()
        ts_s = self.inputs['T'].sv_get()

        surface_s = ensure_nesting_level(surface_s,
                                         2,
                                         data_types=(SvSurface, ))
        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve, ))
        ts_s = ensure_nesting_level(ts_s, 3)

        matrix_out = []
        tangents_out = []
        normals_out = []
        binormals_out = []
        for surfaces_i, curves_i, ts_i in zip_long_repeat(
                surface_s, curve_s, ts_s):
            new_matrices = []
            new_tangents = []
            new_normals = []
            new_binormals = []
            for surface, curve, ts in zip_long_repeat(surfaces_i, curves_i,
                                                      ts_i):
                ts = np.array(ts)

                matrices_np, points, tangents, normals, binormals = curve_frame_on_surface_array(
                    surface, curve, ts)
                curve_matrices = []
                for matrix_np, point in zip(matrices_np, points):
                    matrix = Matrix(matrix_np.tolist()).to_4x4()
                    matrix.translation = Vector(point)
                    curve_matrices.append(matrix)

                if self.join:
                    new_matrices.extend(curve_matrices)
                    new_tangents.extend(tangents.tolist())
                    new_normals.extend(normals.tolist())
                    new_binormals.extend(binormals.tolist())
                else:
                    new_matrices.append(curve_matrices)
                    new_tangents.append(tangents.tolist())
                    new_normals.append(normals.tolist())
                    new_binormals.append(binormals.tolist())

            if self.join:
                matrix_out.extend(new_matrices)
                tangents_out.extend(new_tangents)
                normals_out.extend(new_normals)
                binormals_out.extend(new_binormals)
            else:
                matrix_out.append(new_matrices)
                tangents_out.append(new_tangents)
                normals_out.append(new_normals)
                binormals_out.append(new_binormals)

        self.outputs['Matrix'].sv_set(matrix_out)
        self.outputs['Tangent'].sv_set(tangents_out)
        self.outputs['Normal'].sv_set(normals_out)
        self.outputs['Binormal'].sv_set(binormals_out)