Search in sources :

Example 1 with Properties

use of com.jme3.scene.plugins.blender.objects.Properties in project jmonkeyengine by jMonkeyEngine.

the class MeshHelper method toTemporalMesh.

/**
     * Converts the mesh structure into temporal mesh.
     * The temporal mesh is stored in blender context and here always a clone is being returned because the mesh might
     * be modified by modifiers.
     * 
     * @param meshStructure
     *            the mesh structure
     * @param blenderContext
     *            the blender context
     * @return temporal mesh read from the given structure
     * @throws BlenderFileException
     *             an exception is thrown when problems with reading blend file occur
     */
public TemporalMesh toTemporalMesh(Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
    LOGGER.log(Level.FINE, "Loading temporal mesh named: {0}.", meshStructure.getName());
    TemporalMesh temporalMesh = (TemporalMesh) blenderContext.getLoadedFeature(meshStructure.getOldMemoryAddress(), LoadedDataType.TEMPORAL_MESH);
    if (temporalMesh != null) {
        LOGGER.fine("The mesh is already loaded. Returning its clone.");
        return temporalMesh.clone();
    }
    if ("ID".equals(meshStructure.getType())) {
        LOGGER.fine("Loading mesh from external blend file.");
        return (TemporalMesh) this.loadLibrary(meshStructure);
    }
    String name = meshStructure.getName();
    LOGGER.log(Level.FINE, "Reading mesh: {0}.", name);
    temporalMesh = new TemporalMesh(meshStructure, blenderContext);
    LOGGER.fine("Loading materials.");
    MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
    temporalMesh.setMaterials(materialHelper.getMaterials(meshStructure, blenderContext));
    LOGGER.fine("Reading custom properties.");
    Properties properties = this.loadProperties(meshStructure, blenderContext);
    temporalMesh.setProperties(properties);
    blenderContext.addLoadedFeatures(meshStructure.getOldMemoryAddress(), LoadedDataType.STRUCTURE, meshStructure);
    blenderContext.addLoadedFeatures(meshStructure.getOldMemoryAddress(), LoadedDataType.TEMPORAL_MESH, temporalMesh);
    return temporalMesh.clone();
}
Also used : MaterialHelper(com.jme3.scene.plugins.blender.materials.MaterialHelper) Properties(com.jme3.scene.plugins.blender.objects.Properties)

Example 2 with Properties

use of com.jme3.scene.plugins.blender.objects.Properties in project jmonkeyengine by jMonkeyEngine.

the class TemporalMesh method preparePointsGeometry.

/**
     * The method creates geometries from points.
     * @param result
     *            the list where new geometries will be appended
     * @param meshHelper
     *            the mesh helper
     */
protected void preparePointsGeometry(List<Geometry> result, MeshHelper meshHelper) {
    if (points.size() > 0) {
        LOGGER.fine("Preparing point geometries.");
        MeshBuffers pointBuffers = new MeshBuffers(0);
        for (Point point : points) {
            pointBuffers.append(vertices.get(point.getIndex()), normals.get(point.getIndex()));
        }
        Mesh pointsMesh = new Mesh();
        pointsMesh.setMode(Mode.Points);
        pointsMesh.setPointSize(blenderContext.getBlenderKey().getPointsSize());
        if (pointBuffers.isShortIndexBuffer()) {
            pointsMesh.setBuffer(Type.Index, 1, (ShortBuffer) pointBuffers.getIndexBuffer());
        } else {
            pointsMesh.setBuffer(Type.Index, 1, (IntBuffer) pointBuffers.getIndexBuffer());
        }
        pointsMesh.setBuffer(pointBuffers.getPositionsBuffer());
        pointsMesh.setBuffer(pointBuffers.getNormalsBuffer());
        Geometry pointsGeometry = new Geometry(meshStructure.getName() + (result.size() + 1), pointsMesh);
        pointsGeometry.setMaterial(meshHelper.getBlackUnshadedMaterial(blenderContext));
        if (properties != null && properties.getValue() != null) {
            meshHelper.applyProperties(pointsGeometry, properties);
        }
        result.add(pointsGeometry);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Mesh(com.jme3.scene.Mesh)

Example 3 with Properties

use of com.jme3.scene.plugins.blender.objects.Properties in project jmonkeyengine by jMonkeyEngine.

the class VRAppState method stateAttached.

@Override
public void stateAttached(AppStateManager stateManager) {
    //To change body of generated methods, choose Tools | Templates.
    super.stateAttached(stateManager);
    if (settings == null) {
        settings = new AppSettings(true);
        logger.config("Using default settings.");
    } else {
        logger.config("Using given settings.");
    }
    // Attach VR environment to the application
    if (!environment.isInitialized()) {
        environment.initialize();
    }
    if (environment.isInitialized()) {
        environment.atttach(this, stateManager.getApplication());
    } else {
        logger.severe("Cannot attach VR environment to the VR app state as its not initialized.");
    }
    GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (environment.isInVR() && !environment.compositorAllowed()) {
        // "easy extended" mode
        // setup experimental JFrame on external device
        // first, find the VR device
        GraphicsDevice VRdev = null;
        GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        // pick the display that isn't the default one
        for (GraphicsDevice gd : devs) {
            if (gd != defDev) {
                VRdev = gd;
                break;
            }
        }
        // did we get the VR device?
        if (VRdev != null) {
            // set properties for VR acceleration
            try {
                java.awt.DisplayMode useDM = null;
                int max = 0;
                for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
                    int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
                    if (check > max) {
                        max = check;
                        useDM = dm;
                    }
                }
                // create a window for the VR device
                settings.setWidth(useDM.getWidth());
                settings.setHeight(useDM.getHeight());
                settings.setBitsPerPixel(useDM.getBitDepth());
                settings.setFrequency(useDM.getRefreshRate());
                settings.setSwapBuffers(true);
                // allow vsync on this display
                settings.setVSync(true);
                stateManager.getApplication().setSettings(settings);
                logger.config("Updated underlying application settings.");
                // make sure we are in the right display mode
                if (VRdev.getDisplayMode().equals(useDM) == false) {
                    VRdev.setDisplayMode(useDM);
                }
                return;
            } catch (Exception e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            logger.config("Cannot access to external screen.");
        }
    } else {
        if (!environment.isInVR()) {
            logger.config("Cannot switch to VR mode (VR disabled by user).");
        } else if (!environment.compositorAllowed()) {
            logger.warning("Cannot switch to VR mode (VR not supported).");
        }
    }
    if (!environment.isInVR()) {
        //FIXME: Handling GLFW workaround on MacOS
        boolean macOs = false;
        if (macOs) {
            // GLFW workaround on macs
            settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
            settings.setDepthBits(24);
            settings.setVSync(true);
            // try and read resolution from file in local dir
            File resfile = new File("resolution.txt");
            if (resfile.exists()) {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(resfile));
                    settings.setWidth(Integer.parseInt(br.readLine()));
                    settings.setHeight(Integer.parseInt(br.readLine()));
                    try {
                        settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
                    } catch (Exception e) {
                        settings.setFullscreen(false);
                    }
                    br.close();
                } catch (Exception e) {
                    settings.setWidth(1280);
                    settings.setHeight(720);
                }
            } else {
                settings.setWidth(1280);
                settings.setHeight(720);
                settings.setFullscreen(false);
            }
            settings.setResizable(false);
        }
        settings.setSwapBuffers(true);
    } else {
        // use basic mirroring window, skip settings window
        settings.setSamples(1);
        settings.setWidth(xWin);
        settings.setHeight(yWin);
        settings.setBitsPerPixel(32);
        settings.setFrameRate(0);
        settings.setFrequency(environment.getVRHardware().getDisplayFrequency());
        settings.setFullscreen(false);
        // stop vsyncing on primary monitor!
        settings.setVSync(false);
        settings.setSwapBuffers(environment.isSwapBuffers());
    }
    // Updating application settings
    stateManager.getApplication().setSettings(settings);
    logger.config("Updated underlying application settings.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) AppSettings(com.jme3.system.AppSettings) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 4 with Properties

use of com.jme3.scene.plugins.blender.objects.Properties in project jmonkeyengine by jMonkeyEngine.

the class AbstractBlenderHelper method loadProperties.

/**
     * This method loads the properties if they are available and defined for the structure.
     * @param structure
     *            the structure we read the properties from
     * @param blenderContext
     *            the blender context
     * @return loaded properties or null if they are not available
     * @throws BlenderFileException
     *             an exception is thrown when the blend file is somehow corrupted
     */
protected Properties loadProperties(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
    Properties properties = null;
    Structure id = (Structure) structure.getFieldValue("ID");
    if (id != null) {
        Pointer pProperties = (Pointer) id.getFieldValue("properties");
        if (pProperties.isNotNull()) {
            Structure propertiesStructure = pProperties.fetchData().get(0);
            properties = new Properties();
            properties.load(propertiesStructure, blenderContext);
        }
    }
    return properties;
}
Also used : Pointer(com.jme3.scene.plugins.blender.file.Pointer) Properties(com.jme3.scene.plugins.blender.objects.Properties) Structure(com.jme3.scene.plugins.blender.file.Structure)

Example 5 with Properties

use of com.jme3.scene.plugins.blender.objects.Properties in project jmonkeyengine by jMonkeyEngine.

the class TestCustomAppSettings method testFileSettings.

/**
     * Test Java properties file based AppSettings.
     */
private static void testFileSettings() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    AppSettings settings = new AppSettings(false);
    settings.putBoolean("TestBool", true);
    settings.putInteger("TestInt", 123);
    settings.putString("TestStr", "HelloWorld");
    settings.putFloat("TestFloat", 123.567f);
    // Objects not supported by file settings
    settings.put("TestObj", new Mesh());
    try {
        settings.save(baos);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    AppSettings loadedSettings = new AppSettings(false);
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        loadedSettings.load(bais);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    assertEqual(loadedSettings.getBoolean("TestBool"), true);
    assertEqual(loadedSettings.getInteger("TestInt"), 123);
    assertEqual(loadedSettings.getString("TestStr"), "HelloWorld");
    assertEqual(loadedSettings.get("TestFloat"), 123.567f);
}
Also used : AppSettings(com.jme3.system.AppSettings) ByteArrayInputStream(java.io.ByteArrayInputStream) Mesh(com.jme3.scene.Mesh) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

Geometry (com.jme3.scene.Geometry)4 Mesh (com.jme3.scene.Mesh)4 Pointer (com.jme3.scene.plugins.blender.file.Pointer)3 Structure (com.jme3.scene.plugins.blender.file.Structure)3 AppSettings (com.jme3.system.AppSettings)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Vector3f (com.jme3.math.Vector3f)2 CullHint (com.jme3.scene.Spatial.CullHint)2 Properties (com.jme3.scene.plugins.blender.objects.Properties)2 GraphicsDevice (java.awt.GraphicsDevice)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileReader (java.io.FileReader)2 OSVR (com.jme3.input.vr.OSVR)1 Light (com.jme3.light.Light)1 Material (com.jme3.material.Material)1 Transform (com.jme3.math.Transform)1 Camera (com.jme3.renderer.Camera)1 CameraNode (com.jme3.scene.CameraNode)1