ynput / OpenPype

Main OpenPype repository (to be deprecated)
https://openpype.io
MIT License
280 stars 128 forks source link

search paths, anatomy and multiroot #147

Open antirotor opened 4 years ago

antirotor commented 4 years ago

Use of search paths

Sometimes it is needed to specify search path - basically root where is something searched recursively. One good example is Arnold in Maya:

You can specify path used to resolve other paths for textures, etc. So:

/some/path:/some/other/path

is used to resolve texture relative path foo/bar/baz.tx -> /some/path/foo/bar/baz.tx

To make it more complicated, we need to specify search path using environment variables, so that path can be resolved correctly on linux, windows or macos.

So lets have a root like:

{
    "work": {
        "windows": "//foo/bar/work",
        "linux": "/mnt/foo/bar/work",
        "darwin": "/Volumes/foo/bar/work"
    }
}

This will generate PYPE_ROOT_WORK environment variable set correctly on each platform.

Now lets assume we use templates like this:

{root[name]}/baz/{project[name]}/{hierarchy}/{asset}/work/{task}

(notice the baz part there)

If we then set Arnold search path like this:

[PYPE_ROOT_WORK]

it will be to wide, resulting is search //foo/bar/work and relative paths with baz and project name inside like baz/SomeProject/path/to/texture.tx. That doesn't seem to be right and might be extremelly slow on places with lots of projects (or directory hierarchies).

We could hardcode project like [PYPE_ROOT_WORK]/SomeProject but this will not work with used template.

We could use part of resolved path from template ad add it like:

>>> #pseudocode
>>> template = "{root[name]}/baz/{project[name]}/{hierarchy}/{asset}/work/{task}"
>>> path = template.format(template_data)
>>> resolution_root = path.split(os.pathsep)[1]
>>> print(resolution_root)
baz

and then we could use resolution_root like:

[PYPE_ROOT_WORK]/baz

that makes more sense but resolutio_root or more precisely its index should be user specified. But question is where? It could even be made by more parts of path, like:

>>> resolution_root = path.split(os.pathsep)[1:2]
>>> print(resolution_root)
['baz', 'SomeProject']

[cuID:OP-1040]

iLLiCiTiT commented 4 years ago

Now I see what did you mean, I misunderstood the issue, and yes this may be one of anatomy's methods. I expect that nested resolution may be modifiable. In presets or Anatomy itself?

antirotor commented 4 years ago

Maybe as part of the anatomy. Something like search_path_fragment 🤔

# default.yaml
search_part_fragment : "1:2"
work:
  folder: "{root[work]}/baz/{project[name]}/{hierarchy}/{asset}/work/{task}"

now in python:

>>> search_path = "[{}]{}".format(anatomy.root_environments().keys()[0], anatomy.get_search_fragment())
>>> print(search_path)
[PYPE_WORK_ROOT]baz/SomeProject
mkolar commented 2 years ago

@antirotor I'm not sure this is actually still required. Haven't hear anything related to it for a long time. What do you think?

antirotor commented 2 years ago

@antirotor I'm not sure this is actually still required. Haven't hear anything related to it for a long time. What do you think?

I think it is still valid, related to arnold standins. But I am not sure if anyone is using it with this feature. Without it you can't basically use dynamically Texture Search Path in Arnold Standin...