Package org.jdesktop.wonderland.client.jme.artimport

Examples of org.jdesktop.wonderland.client.jme.artimport.ImportedModel


    public ImportedModel importModel(ImportSettings settings) throws IOException {
        Node modelNode = null;
        URL origFile = settings.getModelURL();

        HashMap<URL, String> textureFilesMapping = new HashMap();
        ImportedModel importedModel = new ImportedModel(origFile, textureFilesMapping);
        SimpleResourceLocator resourceLocator=null;
        try {
            URL baseDir = new URL(origFile.toExternalForm().substring(0, origFile.toExternalForm().lastIndexOf('/')+1));
            resourceLocator = new RecordingResourceLocator(baseDir, textureFilesMapping);
            ResourceLocatorTool.addThreadResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    resourceLocator);
        } catch (URISyntaxException ex) {
            Logger.getLogger(JmeColladaLoader.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
       
        logger.info("Loading MODEL " + origFile.toExternalForm());
        BufferedInputStream in = new BufferedInputStream(origFile.openStream());

        LoaderErrorListener errorListener = new LoaderErrorListener(importedModel, LoaderManager.getLoaderManager().getLoaderListeners());

        modelNode = loadModel(in, getFilename(origFile), true, errorListener);
        in.close();

        ResourceLocatorTool.removeThreadResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, resourceLocator);

        importedModel.setModelBG(modelNode);
        importedModel.setModelLoader(this);
        importedModel.setImportSettings(settings);

        return importedModel;
    }
View Full Code Here


        if (row == -1) {
            LOGGER.warning("Remove with invalid row");
            return;
        }

        ImportedModel ic = imports.remove(row);
        ClientContextJME.getWorldManager().removeEntity(ic.getEntity());
        tableModel.removeRow(row);
    }//GEN-LAST:event_removeBActionPerformed
View Full Code Here

        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    ImportedModel loadedModel = loadModel(settings);
                    listener.loadComplete(loadedModel);
                } catch (IOException ex) {
                    LOGGER.log(Level.SEVERE, null, ex);
                } finally {
                    loadingDialog.setVisible(false);
View Full Code Here

            message = MessageFormat.format(message, fileExtension);
            JOptionPane.showMessageDialog(null, message);
            return null;
        }

        ImportedModel loadedModel = modelLoader.importModel(settings);
        modelBG = loadedModel.getModelBG();

        rootBG.attachChild(modelBG);

        WorldManager wm = ClientContextJME.getWorldManager();

        RenderManager renderManager = wm.getRenderManager();
        ZBufferState buf = (ZBufferState) renderManager.createRendererState(
                RenderState.RS_ZBUFFER);
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);

        MaterialState matState =
                (MaterialState) renderManager.createRendererState(
                RenderState.RS_MATERIAL);
//        matState.setDiffuse(color);
        rootBG.setRenderState(matState);
        rootBG.setRenderState(buf);

        Entity entity = new Entity(loadedModel.getWonderlandName());
        RenderComponent scene = renderManager.createRenderComponent(rootBG);
        entity.addComponent(RenderComponent.class, scene);

        scene.setLightingEnabled(loadedModel.getImportSettings().isLightingEnabled());

        entity.addComponent(TransformProcessorComponent.class,
                new TransformProcessorComponent(wm, modelBG, rootBG));

        wm.addEntity(entity);
        loadedModel.setEntity(entity);

//        findTextures(modelBG);

        return loadedModel;
    }
View Full Code Here

     * Called when the user cancels the load
     */
    void loadCancelled(ImportedModel model) {
        if (editingRow >= 0 && imports.contains(model)) {
            // Restore Position of model
            final ImportedModel imp = model; //imports.get(editingRow);
            final Node tg = imp.getRootBG();
            final Vector3f rot = imp.getOrientation();
            RenderUpdater renderUpdater = new RenderUpdater() {

                public void update(Object arg0) {
                    tg.setLocalRotation(
                            calcRotationMatrix(rot.x, rot.y, rot.z));
                    tg.setLocalTranslation(imp.getTranslation());
                    ClientContextJME.getWorldManager().addToUpdateList(tg);
                }
            };
            ClientContextJME.getWorldManager().addRenderUpdater(
                    renderUpdater, null);
View Full Code Here

     * @param file
     * @return
     */
    @Override
    public ImportedModel importModel(ImportSettings settings) throws IOException {
        ImportedModel importedModel;
        URL modelURL = settings.getModelURL();

        if (!modelURL.getProtocol().equalsIgnoreCase("file")) {
            final String modelURLStr = modelURL.toExternalForm();
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    JOptionPane.showConfirmDialog(null,
                            "Unable to load KMZ from this url "+modelURLStr+
                            "\nPlease use a local kmz file.",
                            "Deploy Error", JOptionPane.OK_OPTION);
                }
            });
            return null;
        }

        try {
            File f = null;
            try {
                // Use the URI.getPath() to decode any escaped characters ie %20
                URI uri = modelURL.toURI();
                String path = uri.getPath();
                f = new File(path);
            } catch (URISyntaxException ex) {
                Logger.getLogger(KmzLoader.class.getName()).log(Level.SEVERE, "Error processing url "+modelURL.toExternalForm(), ex);
                return null;
            }
            if (f==null) {
                logger.warning("Unable to get file for model "+modelURL.toExternalForm());
                JOptionPane.showMessageDialog(null, "Unable to get file for model "+modelURL.toExternalForm(), "Error", JOptionPane.ERROR_MESSAGE);
                return null;
            } else if (!f.canRead()) {
                logger.warning("Can not read file "+f.getAbsolutePath());
                JOptionPane.showMessageDialog(null, "Unable to read file "+f.getAbsolutePath()+"\nPlease check file permissions", "Error", JOptionPane.ERROR_MESSAGE);
                return null;
            }

            ZipFile zipFile = null;
            ZipEntry docKmlEntry = null;
            try {
                zipFile = new ZipFile(f);
                docKmlEntry = zipFile.getEntry("doc.kml");
            } catch(ZipException ze) {
                logger.log(Level.WARNING,"Got a ZipException trying to open file "+f.getAbsolutePath(), ze);
                return null;
            }

            KmlParser parser = new KmlParser();
            InputStream in = zipFile.getInputStream(docKmlEntry);
            try {
                parser.decodeKML(in);
            } catch (Exception ex) {
                Logger.getLogger(KmzLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
            List<KmlParser.KmlModel> models = parser.getModels();

            HashMap<URL, String> textureFilesMapping = new HashMap();
            importedModel = new KmzImportedModel(modelURL, models.get(0).getHref(), textureFilesMapping);

            String zipHost = WlzipManager.getWlzipManager().addZip(zipFile);
            ZipResourceLocator zipResource = new ZipResourceLocator(zipHost, zipFile, textureFilesMapping);
            ResourceLocatorTool.addThreadResourceLocator(
                ResourceLocatorTool.TYPE_TEXTURE,
                zipResource);

          JmeColladaLoader.LoaderErrorListener errorListener = new JmeColladaLoader.LoaderErrorListener(importedModel, LoaderManager.getLoaderManager().getLoaderListeners());

          if (models.size()==1) {
                importedModel.setModelBG(load(zipFile, models.get(0), errorListener));
            } else {
                Node modelBG = new Node();
                for(KmlParser.KmlModel model : models) {
                    modelBG.attachChild(load(zipFile, model, errorListener));
                }
                importedModel.setModelBG(modelBG);
            }
            ResourceLocatorTool.removeThreadResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, zipResource);
            WlzipManager.getWlzipManager().removeZip(zipHost, zipFile);

        } catch (ZipException ex) {
            logger.log(Level.SEVERE, null, ex);
            throw new IOException("Zip Error");
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
            throw ex;
        }

        importedModel.setModelLoader(this);
        settings.setLightingEnabled(false);     // No lighting is the default for SketchUp
        importedModel.setImportSettings(settings);

        return importedModel;
    }
View Full Code Here

        add(jPanel3, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void modelListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_modelListValueChanged
        ImportedModel selection = (ImportedModel) modelList.getSelectedValue();
        Document doc = warningTextArea.getDocument();
        try {
            doc.remove(0, doc.getLength());
        } catch (BadLocationException ex) {
            Logger.getLogger(LoaderWarningsPanel.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

TOP

Related Classes of org.jdesktop.wonderland.client.jme.artimport.ImportedModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.