Resource Locator

Problems building or running Ardor3D, questions about how to use features, etc.

Resource Locator

Postby shinden15 » Wed Mar 28, 2012 12:43 pm

Just run into a a exported binary and/or xml problem. I have this mesh plus some models loaded with collada importer and it's respective texture (defined inside the collada file). When I export the rootNode as a binary or xml the path of the textures stored have a '/' at the beggining. I know its there because of some process the getResource do. Isn't there a way to delete this single character since when one use the importer the path e.g. "/E:/eclipse/1.jpg" to the texture could not be found.

I export the binary as:
Code: Select all
new BinaryExporter().save(spatial, filename);
//where filename is File that defines where and what file name to export


on import of binary
Code: Select all
importedMesh = (Mesh)new XMLImporter().load(filename);
//where filename is File that defines where and what file name to import


I also accessed the texture directly by using ImageIO.read(URL) and seem not to get problem on the '/' at the start
Got two projects due this month. Will use Ardor3D for both.
*Finish one of the projects will post in forums after I got it running on an executable JAR*

Code-Eat-Sleep-Play
shinden15
newcomer
 
Posts: 28
Joined: Thu Mar 08, 2012 4:11 am

Re: Resource Locator

Postby shinden15 » Wed Mar 28, 2012 2:50 pm

I've managed to load the exported files by adding File in ResourceLocatorTool.locateResource

Code: Select all
public static ResourceSource locateResource(final String resourceType, String resourceName) {
        if (resourceName == null) {
            return null;
        }
        //delete extra '/' at the beginning
        String s = resourceName;
        if (s.startsWith("/")) {
            s = s.replaceFirst("/", "");
            resourceName = s;
        }
        try {
            resourceName = URLDecoder.decode(resourceName, "UTF-8");
        } catch (final UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }

        synchronized (_locatorMap) {
            final List<ResourceLocator> bases = _locatorMap.get(resourceType);
            if (bases != null) {
                for (int i = bases.size(); --i >= 0;) {
                    final ResourceLocator loc = bases.get(i);
                    final ResourceSource rVal = loc.locateResource(resourceName);
                    if (rVal != null) {
                        return rVal;
                    }
                }
            }

            try {
                final URL u = ResourceLocatorTool.getClassPathResource(ResourceLocatorTool.class, resourceName);
                if (u != null) {
                    return new URLResourceSource(u);
                }
            } catch (final Exception e) {
                logger.logp(Level.WARNING, ResourceLocatorTool.class.getName(), "locateResource(String, String)",
                        e.getMessage(), e);
            }

            // last resort...
            // File to locate anywhere in the file system and use URLResourceSource(URL) to further parse the data
            try {
                final File file = new File(resourceName);
                final URL url = file.toURI().toURL();
                if (url != null) {
                    return new URLResourceSource(url);
                }
            } catch (final MalformedURLException ex) {
                ex.printStackTrace();
            }

            logger.warning("Unable to locate: " + resourceName);
            return null;
        }
    }


I don't know if this is a good approach or not. If there is a better way without changing the ResourceLocatorTool class I'll be thankful.
Got two projects due this month. Will use Ardor3D for both.
*Finish one of the projects will post in forums after I got it running on an executable JAR*

Code-Eat-Sleep-Play
shinden15
newcomer
 
Posts: 28
Joined: Thu Mar 08, 2012 4:11 am

Re: Resource Locator

Postby renanse » Thu Mar 29, 2012 10:03 am

Did you try adding your own ResourceLocator instead?
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX


Return to HELP!

Who is online

Users browsing this forum: No registered users and 2 guests

cron