Exemple #1
0
def read_point_cloud():
    """
    Read Open3d point clouds and covnert to Houdini geometry

    Based on http://www.open3d.org/docs/tutorial/Basic/working_with_numpy.html
    """
    node = hou.pwd()
    node_geo = node.geometry()
    path = node.parm("path").eval()
    
    pcd_load = open3d.read_point_cloud(path)
    
    if not pcd_load.has_points():
        raise hou.NodeWarning("Geometry does not contain any points.")

    # create numpy arrays
    np_pos = np.asarray(pcd_load.points)
    np_n = np.asarray(pcd_load.normals)
    np_cd = np.asarray(pcd_load.colors)

    # position
    node_geo.createPoints(np_pos)

    # normals
    if pcd_load.has_normals():
        node_geo.addAttrib(hou.attribType.Point, "N", default_value=(0.0, 0.0, 0.0), transform_as_normal=True, create_local_variable=False)
        node_geo.setPointFloatAttribValuesFromString("N", np_n, float_type=hou.numericData.Float64)
    
    # colors
    if pcd_load.has_colors():
        node_geo.addAttrib(hou.attribType.Point, "Cd", default_value=(0.0, 0.0, 0.0), transform_as_normal=False, create_local_variable=False)
        node_geo.setPointFloatAttribValuesFromString("Cd", np_cd, float_type=hou.numericData.Float64)
def call_djv():
    # get current scene sid, change it for save a png
    current_scene = engine.engine.get()
    current_scene_sid = current_scene.get_sid()
    if not current_scene_sid:
        raise hou.NodeWarning("You project is not in the pipeline")
        return
    current_scene_sid.set(ext="png", frame="$F4")

    # we check if the file_path folder exist
    file_path_folder = os.path.dirname(current_scene_sid.path)
    if not os.path.exists(file_path_folder):
        raise hou.NodeWarning("You have no folder to read")
        return

    # we check if the file_path folder is empty
    if len(os.listdir(file_path_folder)) == 0:
        raise hou.NodeWarning("You have no image to read")
        return

    return file_path_folder
Exemple #3
0
    def nodeUpdate():
        """Cook the node.

        This method is called by Houdini when the node is cooking.

        """
        # Get a handle to the node
        self = hou.pwd()

        # Activate the node's warning/error flag based on the severity
        # attribute
        severity = self.parm('severity').evalAsInt()
        message = self.parm('message').evalAsString()
        if severity == 1:
            raise hou.NodeWarning(message)
        elif severity == 2:
            raise hou.NodeError(message)

        # Update the node if it has not beed updated yet and set it's update
        # flag
        if not self.cachedUserData('loaded'):
            hou.phm().loadDataCallback()
            self.setCachedUserData('loaded', True)
def launch():
    # we open the scene
    scene = toolutils.sceneViewer()

    # we create the settings of the flipbook
    settings = scene.flipbookSettings().stash()

    # we create the new output
    current_scene = engine.engine.get()
    current_scene_sid = current_scene.get_sid()
    if not current_scene_sid:
        raise hou.NodeWarning("You project is not in the pipeline")
        return
    current_scene_sid.set(ext="png", frame="$F4")
    print current_scene_sid.path

    # we check if the path already exist, if not we create it
    flipbook_path_save = os.path.dirname(current_scene_sid.path)
    print flipbook_path_save
    flipbook_path_check = os.path.exists(flipbook_path_save)
    if (not flipbook_path_check):
        print "path doesn't exist"
        os.makedirs(flipbook_path_save)
        print "path created"

    # we check if we already have an image
    if (flipbook_path_check and len(os.listdir(flipbook_path_save)) != 0):
        if not hou.ui.displayConfirmation("Overwrite the current flipbook ?"):
            return

    # we set it
    settings.output(current_scene_sid.path)
    settings.frameRange(hou.playbar.playbackRange())

    # we open it
    scene.flipbook(scene.curViewport(), settings)
Exemple #5
0
def read(node, geo, child, type):
    nodePath = node.path()
    function = inspect.stack()[0][3]
    try:
        missingframe = node.evalParm("missingframe")
        enableTile = node.evalParm("enableTile")
        skipInput = node.evalParm("skipInput")
        filePath = node.hm().path.filePath(node)

        dataList = []
        if skipInput or len(node.node("IN").inputs()) == 0:

            g_dataList = []
            if type == "cells":
                if enableTile:
                    get_cell_num = child.inputs()[2].geometry()
                    g_dataList = get_cell_num.attribValue("dataList")
                    g_dataList = [
                        str(int(c)).zfill(5) for c in g_dataList.split(',')
                    ]

                try:
                    _dataList = node.evalParm("dataList").replace(' ', '')
                    dataList = [
                        str(int(c)).zfill(5) for c in _dataList.split(',')
                    ]
                    dataList += g_dataList

                except ValueError:

                    if not g_dataList:
                        if missingframe == 0:
                            raise hou.NodeError("Invalid " + type +
                                                " parameter")
                        else:
                            raise hou.NodeWarning("Invalid " + type +
                                                  " parameter")
                    else:
                        dataList = g_dataList

            elif type == "tiles":
                get_tile_num = child.inputs()[2].geometry()
                try:
                    g_dataList = get_tile_num.attribValue("dataList")
                    g_dataList = [
                        str("x" + t.replace("_", "_y"))
                        for t in g_dataList.split(',')
                    ]
                except:
                    print("No Data List...exiting")
                    return

                if not g_dataList:
                    if missingframe == 0:
                        raise hou.NodeError("Invalid " + type + " parameter")
                    else:
                        raise hou.NodeWarning("Invalid " + type + " parameter")
                else:
                    dataList = g_dataList

        else:
            input_geo = child.inputs()[1].geometry()
            _dataList = input_geo.attribValue("dataList")
            if not _dataList:
                if missingframe == 0:
                    raise hou.NodeError(
                        "'dataList' detail attribute not found on input")
                else:
                    raise hou.NodeWarning(
                        "'dataList' detail attribute not found on input")

            if type == "cells":
                dataList = [str(int(c)).zfill(5) for c in _dataList.split(',')]
            elif type == "tiles":
                dataList = [
                    str("x" + t.replace("_", "_y"))
                    for t in _dataList.split(',')
                ]

        if not dataList:
            if missingframe == 0:
                raise hou.NodeError(type + " parameter is empty")
            else:
                raise hou.NodeWarning(type + " parameter is empty")

        dataList = list(set(dataList))

        for data in dataList:
            if type == "cells":
                file = filePath.replace("%CELLNUM%", data)
            elif type == "tiles":
                file = filePath.replace("%TILENUM%", data)

            if not os.path.exists(file): continue
            if os.path.getsize(file) == 594L: continue

            node.hm().file.load(node, geo, file)

    except (KeyboardInterrupt, SystemExit):
        print("Interrupt requested of " + function + " for " + nodePath +
              "...exiting")
        return
Exemple #6
0
def readPattern(node, geo, child, type):
    nodePath = node.path()
    function = inspect.stack()[0][3]
    try:
        missingframe = node.evalParm("missingframe")
        skipInput = node.evalParm("skipInput")
        enableTile = node.evalParm("enableTile")
        folderSubType = node.hm().path.folderSubType(node)
        label_pattern = node.evalParm("label")
        prefix_pattern = node.evalParm("prefix")
        filePath = node.hm().path.filePath(node)

        dataList = []
        if skipInput or len(node.node("IN").inputs()) == 0:

            g_dataList = []
            if type == "cells":
                if enableTile:
                    get_cell_num = child.inputs()[2].geometry()
                    g_dataList = get_cell_num.attribValue("dataList")
                    g_dataList = [
                        str(int(c)).zfill(5) for c in g_dataList.split(',')
                    ]

                try:
                    _dataList = node.evalParm("dataList").replace(' ', '')
                    dataList = [
                        str(int(c)).zfill(5) for c in _dataList.split(',')
                    ]
                    dataList += g_dataList

                except ValueError:
                    if not g_list:
                        if missingframe == 0:
                            raise hou.NodeError("Invalid data parameter")
                        else:
                            raise hou.NodeWarning("Invalid data parameter")
                    else:
                        dataList = g_dataList

            elif type == "tiles":
                get_tile_num = child.inputs()[2].geometry()
                g_dataList = get_tile_num.attribValue("dataList")
                g_dataList = [
                    str("x" + t.replace("_", "_y"))
                    for t in g_dataList.split(',')
                ]

                if not g_dataList:
                    if missingframe == 0:
                        raise hou.NodeError("Invalid data parameter")
                    else:
                        raise hou.NodeWarning("Invalid data parameter")
                else:
                    dataList = g_dataList

        else:
            input_geo = child.inputs()[1].geometry()
            _dataList = input_geo.attribValue("dataList")
            if not _dataList:
                if missingframe == 0:
                    raise hou.NodeError(
                        "'dataList' detail attribute not found on input")
                else:
                    raise hou.NodeWarning(
                        "'dataList' detail attribute not found on input")

            if type == "cells":
                dataList = [
                    str("x" + t.replace("_", "_y"))
                    for t in _dataList.split(',')
                ]
            if type == "tiles":
                dataList = [str(int(c)).zfill(5) for c in _dataList.split(',')]

        if not dataList:
            if missingframe == 0:
                if missingframe == 0:
                    raise hou.NodeError("data parameter is empty")
                else:
                    raise hou.NodeWarning("data parameter is empty")

        try:
            dataList = list(set(dataList))
            path_root = os.path.dirname(filePath)

            if type == "cells":
                valid_files = [f for f in os.listdir(path_root) if \
                               f.split('_')[-1].split('.', 1)[0] in dataList]
            if type == "tiles":
                valid_files = [f for f in os.listdir(path_root) if \
                               f.split('.')[0][-7:] in dataList]

            for f in valid_files:

                # check if label matches
                if label_pattern and label_pattern != '*':
                    current = f.split(folderSubType + '_')[-1]

                    if type == "cells":
                        file_label = current.split("cell")[0]
                    if type == "tiles":
                        current = current.split('.', 1)[0]
                        file_label = current.replace(current[-8:], '')

                    # doesn't have label
                    if not file_label:
                        continue

                    if not hou.patternMatch(label_pattern, file_label):
                        continue

                # check if prefix matches
                if prefix_pattern and prefix_pattern != '*':
                    _p = f.split(folderSubType)[0]

                    if not _p:
                        continue

                    if not hou.patternMatch(prefix_pattern, _p):
                        continue
                file = path_root + '/' + f
                node.hm().file.load(node, geo, file)

        except WindowsError:
            print("Path error: " + filePath)

    except (KeyboardInterrupt, SystemExit):
        print("Interrupt requested of " + function + " for " + nodePath +
              "...exiting")
        return
Exemple #7
0
    def setDataFromGeometry(self, geo, export_attribs, property_names=None):
        # sets data into geometry
        if not isinstance(geo, hou.Geometry):
            raise hou.Error("Input is not not a valid Houdini Geometry")

        self.clear()
        bindings = {}
        attribs = export_attribs.split(' ')
        if property_names is None:  # use default corresponding table
            bindings = self.defaultBindings
        else:
            propnames = property_names.split(' ')
            for i in xrange(len(attribs)):
                bindings[attribs[i]] = propnames[i]

        retained_attribs = []
        for attrib in attribs:
            geo_attr = geo.findPointAttrib(attrib)
            if geo_attr is not None:
                data_type = geo_attr.dataType()
                if data_type == hou.attribData.Int:
                    str_type = 'int'
                elif data_type == hou.attribData.Float:
                    str_type = 'float'
                components = geo_attr.size()

                retained_attribs.append(geo_attr)
                if components == 1:  # float
                    self.propertyNames.append(bindings[attrib])
                    self.propertyTypes.append(str_type)
                    self.itemstride += 4
                elif components <= 4:  # vector
                    for i in xrange(components):
                        self.propertyNames.append(bindings[attrib] + ".{}".format(self.components[i]))
                        self.propertyTypes.append(str_type)
                        self.itemstride += 4
            else:
                raise hou.NodeWarning("Point attribute not found : {}".format(attrib))

        print("------- {} PROPERTIES --------".format(len(self.propertyNames)))
        for i in xrange(len(self.propertyNames)):
            print("Property : {} ({})".format(self.propertyNames[i], self.propertyTypes[i]))

        points = geo.points()
        numpt = len(points)
        self.itemcount = numpt

        for point in points:
            for i in xrange(len(retained_attribs)):
                attr = retained_attribs[i]
                val = point.attribValue(attr)

                if self.propertyTypes[i] == "float":
                    t = 'f'
                elif self.propertyTypes[i] == "int":
                    t = 'i'

                if attr.size() > 1:
                    for comp in val:
                        pack = struct.pack(t, comp)
                        for byte in pack:
                            self.propertyData.append(byte)
                else:
                    pack = struct.pack(t, val)
                    for byte in pack:
                        self.propertyData.append(byte)