Results 1 to 5 of 5

Thread: Base directory for file referencing

  1. #1
    Gruik
    Guest

    Base directory for file referencing

    Hi,

    I'm doing some kind of Collada scene exporter for my software. The scenes contain several models that are all Collada files.

    So I export the scenes in which all the "instance_geometry" tags reference external files. No problem here (unless you use Blender that doesn't handle this!).

    The problem is this one: now all my models are in a specific folder (with sub-folders) and are referenced with a relative path in the Collada scene files. (absolute paths wouldn't be valid as the software is to be distributed on other computers).
    But what if the base directory of the models changes on the other computers? I need to specify a mesh base directory that can be easily changed.

    So I'd like something like that :
    Code :
    <instance_geometry url=Reference_to_base_dir + Path_relative_to_base_dir#MeshGeometry/>

    where the Reference_to_base_dir is some kind of tag specified at the beginning of the scene file.

    So my questions are :
    - Is it possible to do this?
    - If yes, how so? Where can I create the Reference_to_base_dir tag and how instance_geometries' url can refer to it ?

    Thanks,
    Benjamin[/code]

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    This type of behavior is "built-in" with URIs, which Collada uses heavily. To understand how it works you must know the difference between URIs and URI references. The gory details behind the process of resolving a relative URI reference is explained in the URI spec.

    For your situation, let's say you have a file /home/gruik/scenes/scene1.dae, and you want to instantiate a geometry element with ID 'myGeom' in the file /home/gruik/scenes/scene1/geom.dae. That would look like this:

    <instance_geometry url="scene1/geom.dae#myGeom">

    Pretty simple, right?

  3. #3
    Gruik
    Guest
    Thanks for your quick answer!

    For the URIs, I did get how it works recently and totally understand your example (it's right that it is pretty simple to do)
    But I think I must have badly explained my problem (my bad), because it is more than that.

    Let's say my models are in different directories in /home/gruik/models/ and my scenes in /home/gruik/scenes.
    I reference the models in my scenes exactely like you explained above with something like that :
    <instance_geometry url="../models/geom1/geom.dae#myGeom">

    No problem until there.
    But now let's say one client install the software on his computer and copy the models directory in his directory /home/client/foo/ (and keep the same directories in the models directory)
    Let's say the scenes are in /home/client/scenes.

    Now my instance_geometries' URIs are all wrong !
    So what I'd like to do is have these 2 things :

    - a kind of tag at the beginning of each scene file telling the relative path between the scenes directory and the models one. So in my example something like <MESH_RELATIVE_PATH>../foo/models</MESH_RELATIVE_PATH>

    - and then my instance_geometry above would look something like :
    <instance_geometry url="#MESH_RELATIVE_PATH + /geom1/geom.dae#myGeom">

    Like that, if a client wants to have his models directory at a different relative path from the scenes one, he just have to launch a script that change the value of the MESH_RELATIVE_PATH tag, not the paths of all the models referenced in the scenes. I think it would be a better way to do that because it changes 1 value in each scene file instead if a unknown number.

    So I wanted to know if it is possible to do that. And if it is, how ?

  4. #4
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Ah, I see. In that case I don't think what you're looking for is really possible. The closest thing is the 'base' attribute on the <COLLADA> element, which allows you to define your own base URI for the document. But that base URI will apply to all URI refs in the document, not just the <instance_geometry>s like you want.
    Like that, if a client wants to have his models directory at a different relative path from the scenes one, he just have to launch a script that change the value of the MESH_RELATIVE_PATH tag, not the paths of all the models referenced in the scenes. I think it would be a better way to do that because it changes 1 value in each scene file instead if a unknown number.
    I agree that'd be a better way to do it, but it seems like it wouldn't be all that much harder to write a script to change all the <instance_geometry> URIs.

  5. #5
    Gruik
    Guest
    Well, the base attribute can be useful indeed but not in this case (as i have files referenced which are not in the same directory). So I think the basic solution will be the one here. The script will have much work to do but it is not here to rest

    Thanks for your help sthomas.
    Benjamin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •