Search in sources :

Example 1 with Scene

use of org.jwildfire.create.eden.scene.Scene in project JWildfire by thargor6.

the class FilterKernelVisualisation3dRenderer method createKernelVisualisation.

public SimpleImage createKernelVisualisation(int pWidth, int pHeight) {
    String key = makeKey(pWidth, pHeight);
    SimpleImage img = cache.get(key);
    if (img == null) {
        img = new SimpleImage(pWidth, pHeight);
        if (noiseFilterSize > 0) {
            Scene scene = createScene(pWidth, pHeight);
            double sunflowScale = 10.0;
            double sunflowZScale = 0.6;
            int rectCount = noiseFilterSize;
            double dx = (double) pWidth / (double) rectCount;
            double dy = (double) pHeight / (double) rectCount;
            double w2 = (double) pWidth / 2.0;
            double h2 = (double) pHeight / 2.0;
            double xOff = 0.0, yOff = 0.0;
            for (int i = 0; i < noiseFilterSize; i++) {
                xOff = 0;
                for (int j = 0; j < noiseFilterSize; j++) {
                    double fValue = filter[i][j];
                    Color rectColor;
                    if (fValue >= 0) {
                        int fValueClr = Tools.FTOI(255.0 * fValue);
                        if (fValueClr > 255) {
                            fValueClr = 255;
                        }
                        rectColor = new Color(fValueClr, fValueClr, fValueClr);
                    } else {
                        int fValueClr = Tools.FTOI(-255.0 * (fValue - 0.5));
                        if (fValueClr > 255) {
                            fValueClr = 255;
                        }
                        rectColor = new Color(fValueClr, 0, 0);
                    }
                    addCube(scene, sunflowScale * (xOff - w2) / (double) pWidth, sunflowScale * (yOff - h2) / (double) pHeight, sunflowScale * dx / (double) pWidth, sunflowScale * dy / (double) pHeight, sunflowScale * fValue * sunflowZScale, rectColor);
                    xOff += dx;
                }
                yOff += dy;
            }
            try {
                SunflowAPI api = createSunflowRenderer(scene);
                SunFlowImagePanel imagePanel = new SunFlowImagePanel();
                imagePanel.setBounds(0, 0, pWidth, pHeight);
                api.render(SunflowAPI.DEFAULT_OPTIONS, imagePanel);
                img.setBufferedImage(imagePanel.getImage(), imagePanel.getWidth(), imagePanel.getHeight());
            } catch (Exception e) {
                e.printStackTrace();
                img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
            }
        } else {
            img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
        }
        cache.put(key, img);
    }
    return img;
}
Also used : SunflowAPI(org.sunflow.SunflowAPI) SimpleImage(org.jwildfire.image.SimpleImage) Color(java.awt.Color) Scene(org.jwildfire.create.eden.scene.Scene) IOException(java.io.IOException)

Example 2 with Scene

use of org.jwildfire.create.eden.scene.Scene in project JWildfire by thargor6.

the class EDENController method edenCreateSurfaceScene.

private String edenCreateSurfaceScene() {
    try {
        Scene scene = new Scene();
        scene.addPointLight(0, 0, -200, 0.6);
        scene.addPointLight(-100, 20, -160, 0.8);
        scene.addPointLight(-10, 200, -60, 0.5);
        int width = 800;
        int height = 600;
        double surfWidth = width / 25.0;
        double surfHeight = height / 25.0;
        double surfDepth = MathLib.sqrt(surfWidth * surfWidth + surfHeight * surfHeight) / 100.0;
        List<Creator> creators = new ArrayList<Creator>();
        // creators.add(new SphereCreator(scene));
        creators.add(new BoxCreator(scene));
        List<Transformer> transformers = new ArrayList<Transformer>();
        transformers.add(new Transformer1(scene));
        transformers.add(new Transformer2(scene));
        for (Creator creator : creators) {
            creator.create();
        }
        Map<Transformer, Set<VisibleSceneElement>> expandedMap = new HashMap<Transformer, Set<VisibleSceneElement>>();
        for (int i = 0; i < 7; i++) {
            for (Transformer transformer : transformers) {
                Set<VisibleSceneElement> expandedSet = expandedMap.get(transformer);
                if (expandedSet == null) {
                    expandedSet = new HashSet<VisibleSceneElement>();
                    expandedMap.put(transformer, expandedSet);
                }
                List<VisibleSceneElement> elements = scene.getAllVisibleElements();
                for (VisibleSceneElement element : elements) {
                    if (!expandedSet.contains(element)) {
                        VisibleSceneElement copy = element.clone();
                        transformer.transform(copy);
                        expandedSet.add(element);
                    }
                }
            }
        }
        System.out.println("ELEMENTS: " + scene.getAllVisibleElements().size());
        return new SunflowExporter().exportScene(scene);
    } catch (Exception ex) {
        Unchecker.rethrow(ex);
        return null;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Scene(org.jwildfire.create.eden.scene.Scene) IOException(java.io.IOException) VisibleSceneElement(org.jwildfire.create.eden.scene.VisibleSceneElement) SunflowExporter(org.jwildfire.create.eden.export.SunflowExporter)

Example 3 with Scene

use of org.jwildfire.create.eden.scene.Scene in project JWildfire by thargor6.

the class AddSceneObjectsVisitor method addPositionableSceneElement.

private void addPositionableSceneElement(PositionableSceneElement pSceneElement) {
    Matrix4 matrix = calcTransform(pSceneElement);
    if (pSceneElement instanceof Sphere) {
        Sphere sphere = (Sphere) pSceneElement;
        if (useMatrix) {
            sceneBuilder.addSphere().withShader(sphere.getMaterial()).withTransform().withMatrix(matrix);
        } else {
            sceneBuilder.addSphere().withShader(sphere.getMaterial()).withTransform().withScaleX(sphere.getSize().getX()).withScaleY(sphere.getSize().getY()).withScaleZ(sphere.getSize().getZ()).withTranslateX(sphere.getPosition().getX()).withTranslateY(sphere.getPosition().getY()).withTranslateZ(sphere.getPosition().getZ());
        }
    } else if (pSceneElement instanceof Cylinder) {
        Cylinder cylinder = (Cylinder) pSceneElement;
        if (useMatrix) {
            sceneBuilder.addCylinder().withShader(cylinder.getMaterial()).withTransform().withMatrix(matrix);
        } else {
            sceneBuilder.addCylinder().withShader(cylinder.getMaterial()).withTransform().withScaleX(cylinder.getSize().getX()).withScaleY(cylinder.getSize().getY()).withScaleZ(cylinder.getSize().getZ()).withTranslateX(cylinder.getPosition().getX()).withTranslateY(cylinder.getPosition().getY()).withTranslateZ(cylinder.getPosition().getZ()).withRotateX(cylinder.getOrientation().getAlpha()).withRotateY(cylinder.getOrientation().getBeta()).withRotateZ(cylinder.getOrientation().getGamma());
        }
    } else if (pSceneElement instanceof Box) {
        Box box = (Box) pSceneElement;
        if (useMatrix) {
            sceneBuilder.addBox().withShader(box.getMaterial()).withTransform().withMatrix(matrix);
        } else {
            sceneBuilder.addBox().withShader(box.getMaterial()).withTransform().withScaleX(box.getSize().getX()).withScaleY(box.getSize().getY()).withScaleZ(box.getSize().getZ()).withTranslateX(box.getPosition().getX()).withTranslateY(box.getPosition().getY()).withTranslateZ(box.getPosition().getZ()).withRotateX(box.getOrientation().getAlpha()).withRotateY(box.getOrientation().getBeta()).withRotateZ(box.getOrientation().getGamma());
        }
    } else if (pSceneElement instanceof Mesh) {
        Mesh mesh = (Mesh) pSceneElement;
        if (useMatrix) {
            sceneBuilder.addMesh().withShader(mesh.getMaterial()).withMesh(mesh).withTransform().withMatrix(matrix);
        } else {
            sceneBuilder.addMesh().withShader(mesh.getMaterial()).withMesh(mesh).withTransform().withScaleX(mesh.getSize().getX()).withScaleY(mesh.getSize().getY()).withScaleZ(mesh.getSize().getZ()).withTranslateX(mesh.getPosition().getX()).withTranslateY(mesh.getPosition().getY()).withTranslateZ(mesh.getPosition().getZ());
        }
    } else if (pSceneElement instanceof PointLight) {
        PointLight light = (PointLight) pSceneElement;
        sceneBuilder.addLight().withType(LightType.POINT).withColor(light.getColor().getR(), light.getColor().getG(), light.getColor().getB()).withP(light.getPosition().getX(), light.getPosition().getY(), light.getPosition().getZ()).withPower(light.getIntensity() * 2000000.0);
    } else if (pSceneElement instanceof SkyLight) {
        SkyLight light = (SkyLight) pSceneElement;
        sceneBuilder.addSkyLight().withUp(light.getUp().getX(), light.getUp().getY(), light.getUp().getZ()).withEast(light.getEast().getX(), light.getEast().getY(), light.getEast().getZ()).withSundir(light.getSundir().getX(), light.getSundir().getY(), light.getSundir().getZ()).withTurbidity(light.getTurbidity()).withSamples(light.getSamples());
    } else if (pSceneElement instanceof Camera) {
        Camera camera = (Camera) pSceneElement;
        sceneBuilder.openCamera().withType(CameraType.PINHOLE).withEye(camera.getEye().getX(), camera.getEye().getY(), camera.getEye().getZ()).withTarget(camera.getTarget().getX(), camera.getTarget().getY(), camera.getTarget().getZ()).withUp(camera.getUp().getX(), camera.getUp().getY(), camera.getUp().getZ()).withFov(camera.getFov()).withAspect(camera.getAspect());
    } else if (pSceneElement instanceof Scene || pSceneElement instanceof MaterialGroup) {
    } else {
        System.out.println("Unknown positionable element " + pSceneElement);
    }
}
Also used : Sphere(org.jwildfire.create.eden.scene.primitive.Sphere) Cylinder(org.jwildfire.create.eden.scene.primitive.Cylinder) SkyLight(org.jwildfire.create.eden.scene.light.SkyLight) MaterialGroup(org.jwildfire.create.eden.scene.MaterialGroup) Mesh(org.jwildfire.create.eden.scene.primitive.Mesh) Box(org.jwildfire.create.eden.scene.primitive.Box) Camera(org.jwildfire.create.eden.scene.camera.Camera) PointLight(org.jwildfire.create.eden.scene.light.PointLight) Scene(org.jwildfire.create.eden.scene.Scene) Matrix4(org.sunflow.math.Matrix4)

Example 4 with Scene

use of org.jwildfire.create.eden.scene.Scene in project JWildfire by thargor6.

the class FilterKernelVisualisation3dRenderer method createScene.

private Scene createScene(int pWidth, int pHeight) {
    Scene scene = new Scene();
    SkyLight light = scene.addSkyLight();
    light.setUp(0.0, 0.0, 1.0);
    light.setEast(0.0, 1.0, 0.0);
    light.setSundir(1.0, -1.0, 0.31);
    light.setTurbidity(1.8);
    light.setSamples(16);
    Camera camera = scene.getCamera();
    camera.setEye(12.0, 11.0, 15.0);
    camera.setTarget(0.0, 0.0, 2.0);
    camera.setUp(0.0, 0.0, 1.0);
    camera.setFov(32.0);
    camera.setAspect(1.0);
    scene.setImageWidth(pWidth);
    scene.setImageHeight(pHeight);
    scene.getCamera().setAspect((double) pWidth / (double) pHeight);
    return scene;
}
Also used : SkyLight(org.jwildfire.create.eden.scene.light.SkyLight) Camera(org.jwildfire.create.eden.scene.camera.Camera) Scene(org.jwildfire.create.eden.scene.Scene)

Aggregations

Scene (org.jwildfire.create.eden.scene.Scene)4 IOException (java.io.IOException)2 Camera (org.jwildfire.create.eden.scene.camera.Camera)2 SkyLight (org.jwildfire.create.eden.scene.light.SkyLight)2 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SunflowExporter (org.jwildfire.create.eden.export.SunflowExporter)1 MaterialGroup (org.jwildfire.create.eden.scene.MaterialGroup)1 VisibleSceneElement (org.jwildfire.create.eden.scene.VisibleSceneElement)1 PointLight (org.jwildfire.create.eden.scene.light.PointLight)1 Box (org.jwildfire.create.eden.scene.primitive.Box)1 Cylinder (org.jwildfire.create.eden.scene.primitive.Cylinder)1 Mesh (org.jwildfire.create.eden.scene.primitive.Mesh)1 Sphere (org.jwildfire.create.eden.scene.primitive.Sphere)1 SimpleImage (org.jwildfire.image.SimpleImage)1 SunflowAPI (org.sunflow.SunflowAPI)1 Matrix4 (org.sunflow.math.Matrix4)1