Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Houdini: support for id attribute for Houdini -> Maya lookdev #3312

Closed
antirotor opened this issue Jun 10, 2022 · 2 comments
Closed

Houdini: support for id attribute for Houdini -> Maya lookdev #3312

antirotor opened this issue Jun 10, 2022 · 2 comments
Assignees
Labels
host: Houdini type: enhancement Enhancements to existing functionality

Comments

@antirotor
Copy link
Member

antirotor commented Jun 10, 2022

Feature

Houdini currently doesn't generate and add cbId equivalent attribute so when you publish alembics from Houdini and you want to use them for lookdev in Maya, it will not work.

There are few options to handle it:

  • provide SOP level generator for Ids (but it might get tricky with more complex setups)
  • add support for paths in Maya look assigner (but that won't add feature parity between maya / houdini)

[cuID:OP-3390]

@BigRoy
Copy link
Collaborator

BigRoy commented Jun 10, 2022

For what it's worth - this is what we had sometimes used in a Python node in SOPs level in Houdini to create path consistent cbId values:

NEW
Updated to match some of the recent OpenPype api refactoring

import random
import uuid
from openpype.pipeline.context_tools import get_current_project_asset


def generate_id(path, asset_id):
    """Returns new unique ids for the given nodes.
    Note: This does not assign the new ids, it only generates the values.
    Args:
        asset_id (str or bson.ObjectId): The database id for the *asset* to
            generate for.
    Returns:
        str: single cbId
    """
    uuid_ = str(uuid.uuid3(uuid.NAMESPACE_DNS, path))
    _, uid = str(uuid_).rsplit("-", 1)
    unique_id = "{}:{}".format(asset_id, uid)
    return unique_id
    

# The seed should be random everywhere you create it but consistent in your Python node
# so that next time you open the scene it generates the same output.
seed_num = 0
random.seed(seed_num)

# Get the asset ID from the database for the asset of current context
asset_doc = get_current_project_asset(fields=["_id"])
assert asset_doc, "No current asset found in Session"
asset_id = asset_doc['_id']
    
    
cbId_attrib = geo.addAttrib(hou.attribType.Prim, "cbId", '')
prims = geo.prims()
for prim in prims:
    path = prim.attribValue('path');
    cbId = generate_id(path, asset_id)
    prim.setAttribValue(cbId_attrib, cbId)

OLD

import random
import uuid
import avalon.io as io
import avalon.api as api


def generate_id(path, asset_id):
    """Returns new unique ids for the given nodes.
    Note: This does not assign the new ids, it only generates the values.
    Args:
        asset_id (str or bson.ObjectId): The database id for the *asset* to
            generate for.
    Returns:
        str: single cbId
    """
    uuid_ = str(uuid.uuid3(uuid.NAMESPACE_DNS, path))
    _, uid = str(uuid_).rsplit("-", 1)
    unique_id = "{}:{}".format(asset_id, uid)
    return unique_id
    

# The seed should be random everywhere you create it but consistent in your Python node
# so that next time you open the scene it generates the same output.
seed_num = 0
random.seed(seed_num)

# Get the asset ID from the database for the asset of current context
asset_data = io.find_one({"type": "asset",
                          "name": api.Session["AVALON_ASSET"]},
                         projection={"_id": True})
assert asset_data, "No current asset found in Session"
asset_id = asset_data['_id']
    
    
cbId_attrib = geo.addAttrib(hou.attribType.Prim, "cbId", '')
prims = geo.prims()
for prim in prims:
    path = prim.attribValue('path');
    cbId = generate_id(path, asset_id)
    prim.setAttribValue(cbId_attrib, cbId)

Notes:

  • This code is based on Avalon and not on OpenPype - so some logic conversion would be needed.
  • As in Maya this would make an id based on the current asset + shape id (which in this case is not random uuid but based on the path of the geometry (The houdini primitive path attribute on the geometry)
  • If you wanted to have the same paths/names in the same asset but still have a unique id I believe you could change the seed_num value so that it'd still generate different ids.

It's important however to understand that I have never found a way to export from Houdini to Alembic cbId attributes that load into Maya with a unique id on the transform node and the shape node. This is due to Houdini not having a similar transform/shape separation on SOPs level. This would be crucial to get cbId attributes in a way like they are also created in Maya.

@BigRoy
Copy link
Collaborator

BigRoy commented Jul 4, 2024

The cbId workflow has been on its way out for a large part. There have been more discussions about path based assignments, also because it aligns with MaterialX and USD and with #2723 closed and providing other options for looks in Houdini this is less relevant to Houdini.

I'm closing this until there's a request to focus more on this in AYON. Feel free to re-open on ayon-houdini. Since it may very well be relevant still for Houdini->Maya workflow until USD is more capable in Maya there may be merit in transferring the issue - however it also has been lingering since June 10, 2022 without much noise around it.

@BigRoy BigRoy closed this as completed Jul 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
host: Houdini type: enhancement Enhancements to existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants