<commit_before>from .rman_mesh_translator import RmanMeshTranslator
from ..rman_sg_nodes.rman_sg_curve import RmanSgCurve
from ..rman_utils import object_utils
from ..rman_utils import string_utils
from ..rman_utils import property_utils

import bpy

def get_curve(curve):
    splines = []

    for spline in curve.splines:
        P = []
        width = []
        npt = len(spline.bezier_points) * 3

        for bp in spline.bezier_points:
            P.extend(bp.handle_left)
            P.extend(bp.co)
            P.extend(bp.handle_right)
            width.append(bp.radius * 0.01)

        basis = ["BezierBasis", 3, "BezierBasis", 3]
        if spline.use_cyclic_u:
            period = 'periodic'
            # wrap the initial handle around to the end, to begin on the CV
            P = P[3:] + P[:3]
        else:
            period = 'nonperiodic'
            # remove the two unused handles
            npt -= 2
            P = P[3:-3]

        name = spline.id_data.name
        splines.append((P, width, npt, basis, period, name))

    return splines      

class RmanCurveTranslator(RmanMeshTranslator):

    def __init__(self, rman_scene):
        super().__init__(rman_scene)
        self.bl_type = 'CURVE'       

    def export(self, ob, db_name):
        is_mesh = False
        if len(ob.data.splines) < 1:
            sg_node = self.rman_scene.sg_scene.CreateMesh(db_name)
            is_mesh = True
        else:
            sg_node = self.rman_scene.sg_scene.CreateGroup(db_name)

        rman_sg_curve = RmanSgCurve(self.rman_scene, sg_node, db_name)
        rman_sg_curve.is_mesh = is_mesh

        if is_mesh and self.rman_scene.do_motion_blur:
            rman_sg_curve.is_transforming = object_utils.is_transforming(ob)
            rman_sg_curve.is_deforming = object_utils._is_deforming_(ob)

        return rman_sg_curve

    def export_deform_sample(self, rman_sg_curve, ob, time_sample):
        if rman_sg_curve.is_mesh:
            super().export_deform_sample(rman_sg_curve, ob, time_sample)

    def export_object_primvars(self, ob, rman_sg_node):
        if rman_sg_node.is_mesh:
            super().export_object_primvars(ob, rman_sg_node)

    def update(self, ob, rman_sg_curve):

        if rman_sg_curve.is_mesh:
            super().update(ob, rman_sg_curve)
            return True    

        for c in [ rman_sg_curve.sg_node.GetChild(i) for i in range(0, rman_sg_curve.sg_node.GetNumChildren())]:
            rman_sg_curve.sg_node.RemoveChild(c)
            self.rman_scene.sg_scene.DeleteDagNode(c)             

        curves = get_curve(ob.data)
        for P, width, npt, basis, period, name in curves:
            curves_sg = self.rman_scene.sg_scene.CreateCurves(name)
            curves_sg.Define(self.rman_scene.rman.Tokens.Rix.k_cubic, period, "bezier", 1, int(len(P)/3))
            
            primvar = curves_sg.GetPrimVars()
            primvar.SetPointDetail(self.rman_scene.rman.Tokens.Rix.k_P, P, "vertex")   
            primvar.SetIntegerDetail(self.rman_scene.rman.Tokens.Rix.k_Ri_nvertices, [npt], "uniform")
            if width:
                primvar.SetFloatDetail(self.rman_scene.rman.Tokens.Rix.k_width, width, "vertex")
            curves_sg.SetPrimVars(primvar)

            rman_sg_curve.sg_node.AddChild(curves_sg)        <commit_msg>Extra error checking for curve translator<commit_after>from .rman_mesh_translator import RmanMeshTranslator
from ..rman_sg_nodes.rman_sg_curve import RmanSgCurve
from ..rman_utils import object_utils
from ..rman_utils import string_utils
from ..rman_utils import property_utils

import bpy

def get_curve(curve):
    splines = []

    for spline in curve.splines:
        P = []
        width = []
        npt = len(spline.bezier_points) * 3

        for bp in spline.bezier_points:
            P.extend(bp.handle_left)
            P.extend(bp.co)
            P.extend(bp.handle_right)
            width.append(bp.radius * 0.01)

        basis = ["BezierBasis", 3, "BezierBasis", 3]
        if spline.use_cyclic_u:
            period = 'periodic'
            # wrap the initial handle around to the end, to begin on the CV
            P = P[3:] + P[:3]
        else:
            period = 'nonperiodic'
            # remove the two unused handles
            npt -= 2
            P = P[3:-3]

        name = spline.id_data.name
        splines.append((P, width, npt, basis, period, name))

    return splines      

class RmanCurveTranslator(RmanMeshTranslator):

    def __init__(self, rman_scene):
        super().__init__(rman_scene)
        self.bl_type = 'CURVE'       

    def export(self, ob, db_name):
        is_mesh = False
        if len(ob.data.splines) < 1:
            sg_node = self.rman_scene.sg_scene.CreateMesh(db_name)
            is_mesh = True
        else:
            l = ob.data.extrude + ob.data.bevel_depth
            if l > 0:
                sg_node = self.rman_scene.sg_scene.CreateMesh(db_name)
                is_mesh = True                            
            else:
                sg_node = self.rman_scene.sg_scene.CreateGroup(db_name)

        rman_sg_curve = RmanSgCurve(self.rman_scene, sg_node, db_name)
        rman_sg_curve.is_mesh = is_mesh

        if is_mesh and self.rman_scene.do_motion_blur:
            rman_sg_curve.is_transforming = object_utils.is_transforming(ob)
            rman_sg_curve.is_deforming = object_utils._is_deforming_(ob)

        return rman_sg_curve

    def export_deform_sample(self, rman_sg_curve, ob, time_sample):
        if rman_sg_curve.is_mesh:
            super().export_deform_sample(rman_sg_curve, ob, time_sample)

    def export_object_primvars(self, ob, rman_sg_node):
        if rman_sg_node.is_mesh:
            super().export_object_primvars(ob, rman_sg_node)

    def update(self, ob, rman_sg_curve):

        if rman_sg_curve.is_mesh:
            super().update(ob, rman_sg_curve)
            return True    

        for c in [ rman_sg_curve.sg_node.GetChild(i) for i in range(0, rman_sg_curve.sg_node.GetNumChildren())]:
            rman_sg_curve.sg_node.RemoveChild(c)
            self.rman_scene.sg_scene.DeleteDagNode(c)             

        curves = get_curve(ob.data)
        for P, width, npt, basis, period, name in curves:
            num_pts = int(len(P)/3)
            if num_pts < 1:
                continue
            curves_sg = self.rman_scene.sg_scene.CreateCurves(name)
            curves_sg.Define(self.rman_scene.rman.Tokens.Rix.k_cubic, period, "bezier", 1, num_pts)
            
            primvar = curves_sg.GetPrimVars()
            primvar.SetPointDetail(self.rman_scene.rman.Tokens.Rix.k_P, P, "vertex")   
            primvar.SetIntegerDetail(self.rman_scene.rman.Tokens.Rix.k_Ri_nvertices, [npt], "uniform")
            if width:
                primvar.SetFloatDetail(self.rman_scene.rman.Tokens.Rix.k_width, width, "vertex")
            curves_sg.SetPrimVars(primvar)

            rman_sg_curve.sg_node.AddChild(curves_sg)        
{'fraction_non_alphanumeric': 0.09275985663082437, 'fraction_numerical': 0.004587813620071685, 'mean_word_length': 2.198532783127006, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254778', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2371, 'n_words': 426}