001: /*
002: * $RCSfile: Collada.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.1 $
041: * $Date: 2007/08/28 16:44:33 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.loaders.collada;
046:
047: import com.sun.j3d.loaders.IncorrectFormatException;
048: import com.sun.j3d.loaders.LoaderBase;
049: import com.sun.j3d.loaders.ParsingErrorException;
050: import com.sun.j3d.loaders.Scene;
051: import com.sun.j3d.loaders.SceneBase;
052: import java.io.File;
053: import java.io.FileNotFoundException;
054: import java.io.Reader;
055: import java.net.URL;
056: import java.util.List;
057: import java.util.logging.Level;
058: import java.util.logging.Logger;
059: import javax.media.j3d.BranchGroup;
060: import javax.xml.bind.JAXBContext;
061: import javax.xml.bind.JAXBException;
062: import javax.xml.bind.Unmarshaller;
063: import org.collada.colladaschema.Asset;
064: import org.collada.colladaschema.COLLADA;
065: import org.collada.colladaschema.Extra;
066: import org.collada.colladaschema.InstanceWithExtra;
067: import org.jdesktop.j3d.loaders.collada.xml_walker.Processor;
068: import org.jdesktop.j3d.loaders.collada.xml_walker.ProcessorFactory;
069:
070: /**
071: *
072: * @author paulby
073: */
074: public class Collada extends LoaderBase {
075:
076: private Logger logger = Logger.getLogger("collada.processor");
077:
078: public Collada() {
079: }
080:
081: public Scene load(String filename) throws FileNotFoundException,
082: IncorrectFormatException, ParsingErrorException {
083: try {
084: javax.xml.bind.JAXBContext jc = javax.xml.bind.JAXBContext
085: .newInstance("org.collada.colladaschema");
086: javax.xml.bind.Unmarshaller unmarshaller = jc
087: .createUnmarshaller();
088: org.collada.colladaschema.COLLADA collada = (org.collada.colladaschema.COLLADA) unmarshaller
089: .unmarshal(new java.io.File(filename));
090:
091: return doLoad(collada);
092: } catch (JAXBException ex) {
093: Logger.getLogger("global").log(Level.SEVERE, null, ex);
094: }
095:
096: return null;
097: }
098:
099: public Scene load(URL arg0) throws FileNotFoundException,
100: IncorrectFormatException, ParsingErrorException {
101: throw new UnsupportedOperationException("Not supported yet.");
102: }
103:
104: public Scene load(Reader arg0) throws FileNotFoundException,
105: IncorrectFormatException, ParsingErrorException {
106: throw new UnsupportedOperationException("Not supported yet.");
107: }
108:
109: private Scene doLoad(COLLADA collada) {
110: BranchGroup rootBG = new BranchGroup();
111:
112: System.out.println("Base " + collada.getBase());
113: System.out.println("Version " + collada.getVersion());
114:
115: Asset asset = collada.getAsset();
116: Asset.Unit unit = asset.getUnit();
117: System.out.println("Units " + unit.getMeter() + " "
118: + unit.getName());
119:
120: List lib = collada
121: .getLibraryLightsAndLibraryGeometriesAndLibraryAnimationClips();
122: System.out.println("Library");
123: for (Object o : lib) {
124: Processor p = ProcessorFactory.createProcessor(o, null);
125: if (p != null)
126: p.createSceneGraph(rootBG);
127: }
128:
129: COLLADA.Scene scene = collada.getScene();
130: List<Extra> list = scene.getExtras();
131: StringBuilder builder = new StringBuilder();
132: for (Extra e : list)
133: builder.append(e + "; ");
134: logger.info("Extras not implemented : " + builder.toString());
135:
136: InstanceWithExtra instanceVisualScene = scene
137: .getInstanceVisualScene();
138: logger.info("Visual Scene not implemented "
139: + instanceVisualScene.getName());
140:
141: List<InstanceWithExtra> in = scene.getInstancePhysicsScenes();
142: for (InstanceWithExtra iwe : in)
143: logger.info("InstanceWithExtra not implemented "
144: + iwe.getName());
145:
146: SceneBase ret = new SceneBase();
147: ret.setSceneGroup(rootBG);
148:
149: return ret;
150: }
151:
152: }
|