类javafx.scene.AmbientLight源码实例Demo

下面列出了怎么用javafx.scene.AmbientLight的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FXyzLib   文件: Drag3DObject.java
private void loadCamera(Scene scene) {
    //initialize camera
    camera = new PerspectiveCamera(true);
    camera.setVerticalFieldOfView(RUN_JASON);

    //setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(100000.0);
    camera.setTranslateZ(-5000);
    cameraTransform.ry.setAngle(0.0);
    cameraTransform.rx.setAngle(-45.0);

    //add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.GAINSBORO);
    cameraTransform.getChildren().add(light);
    cameraTransform.getChildren().add(new AmbientLight(Color.WHITE));
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    //attach camera to scene
    scene.setCamera(camera);

}
 
源代码2 项目: FXyzLib   文件: CubeWorld.java
private void init(){
    redMaterial.setDiffuseColor(Color.DARKRED);
    redMaterial.setSpecularColor(Color.RED);
    greenMaterial.setDiffuseColor(Color.DARKGREEN);
    greenMaterial.setSpecularColor(Color.GREEN);
    blueMaterial.setDiffuseColor(Color.DARKBLUE);
    blueMaterial.setSpecularColor(Color.BLUE);  
    
    buildAxes(axesSize, axesThickness);
    buildPanels(axesSize);
    buildGrids(axesSize, gridLineSpacing);
    buildEventHandlers();        
    getChildren().add(cubeWorldChildren); //Holds ScatterPlot data
    if(selfLightEnabled) {
        AmbientLight light = new AmbientLight(Color.WHITE);
        getChildren().add(light);
    }
}
 
源代码3 项目: FXyzLib   文件: ShapeContainer.java
public ShapeContainer(T shape) {
    this.shape = shape;
    this.material = new PhongMaterial();
    this.emissive = new PointLight();
    this.selfIllumination = new AmbientLight();
    
    this.selfIllumination.getScope().add(ShapeContainer.this);
    initialize();
}
 
源代码4 项目: strangefx   文件: Qubit3D.java
private void createQubit() {
    PerspectiveCamera camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.getTransforms().addAll(rotateX, rotateY, new Translate(0, 0, -200));
 
    FrustumMesh plane = new FrustumMesh(50, 50, 1, 1, new Point3D(0, -0.5f, 0), new Point3D(0, 0.5f, 0));
    plane.setMaterial(new PhongMaterial(Color.web("#ccdd3320")));
    
    SegmentedSphereMesh innerSphere = new SegmentedSphereMesh(40, 0, 0, 50, new Point3D(0, 0, 0));
    innerSphere.setMaterial(new PhongMaterial(Color.web("#ff800080")));
    
    SegmentedSphereMesh frameSphere = new SegmentedSphereMesh(20, 0, 0, 50, new Point3D(0, 0, 0));
    frameSphere.setMaterial(new PhongMaterial(Color.BLACK));
    frameSphere.setDrawMode(DrawMode.LINE);
    
    FrustumMesh rod = new FrustumMesh(2, 2, 1, 1, new Point3D(0, 0, 0), new Point3D(50, 0, 0));
    rod.setMaterial(new PhongMaterial(Color.web("#0080ff")));
    
    SegmentedSphereMesh smallSphere = new SegmentedSphereMesh(20, 0, 0, 4, new Point3D(50, 0, 0));
    smallSphere.setMaterial(new PhongMaterial(Color.web("#0080ff")));
    
    rodSphere = new Group(smallSphere, rod);
    Group group = new Group(plane, rodSphere, innerSphere, frameSphere, new AmbientLight(Color.BISQUE));
    
    SubScene subScene = new SubScene(group, 100, 100, true, SceneAntialiasing.BALANCED);
    subScene.setCamera(camera);
    
    subScene.setOnMousePressed(event -> {
        mouseOldX = event.getSceneX();
        mouseOldY = event.getSceneY();
    });

    subScene.setOnMouseDragged(event -> {
        rotateX.setAngle(rotateX.getAngle() - (event.getSceneY() - mouseOldY));
        rotateY.setAngle(rotateY.getAngle() + (event.getSceneX() - mouseOldX));
        mouseOldX = event.getSceneX();
        mouseOldY = event.getSceneY();
    });
    
    getChildren().add(subScene);
    
    rodSphere.getTransforms().setAll(myRotate);
}
 
源代码5 项目: mars-sim   文件: Simple3DSphereApp.java
public Parent createContent() throws Exception {

        Image dImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-d.jpg").toExternalForm());
        Image nImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-n.jpg").toExternalForm());
        Image sImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-s.jpg").toExternalForm());
        Image siImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-l.jpg").toExternalForm());

        material = new PhongMaterial();
        material.setDiffuseColor(Color.WHITE);
        material.diffuseMapProperty().bind(
                Bindings.when(diffuseMap).then(dImage).otherwise((Image) null));
        material.setSpecularColor(Color.TRANSPARENT);
        material.specularMapProperty().bind(
                Bindings.when(specularMap).then(sImage).otherwise((Image) null));
        material.bumpMapProperty().bind(
                Bindings.when(bumpMap).then(nImage).otherwise((Image) null));
        material.selfIlluminationMapProperty().bind(
                Bindings.when(selfIlluminationMap).then(siImage).otherwise((Image) null));

        earth = new Sphere(5);
        earth.setMaterial(material);
        earth.setRotationAxis(Rotate.Y_AXIS);


        // Create and position camera
        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.getTransforms().addAll(
                new Rotate(-20, Rotate.Y_AXIS),
                new Rotate(-20, Rotate.X_AXIS),
                new Translate(0, 0, -20));

        sun = new PointLight(Color.rgb(255, 243, 234));
        sun.translateXProperty().bind(sunDistance.multiply(-0.82));
        sun.translateYProperty().bind(sunDistance.multiply(-0.41));
        sun.translateZProperty().bind(sunDistance.multiply(-0.41));
        sun.lightOnProperty().bind(sunLight);

        AmbientLight ambient = new AmbientLight(Color.rgb(1, 1, 1));

        // Build the Scene Graph
        Group root = new Group();
        root.getChildren().add(camera);
        root.getChildren().add(earth);
        root.getChildren().add(sun);
        root.getChildren().add(ambient);

        RotateTransition rt = new RotateTransition(Duration.seconds(24), earth);
        rt.setByAngle(360);
        rt.setInterpolator(Interpolator.LINEAR);
        rt.setCycleCount(Animation.INDEFINITE);
        rt.play();

        // Use a SubScene
        SubScene subScene = new SubScene(root, 400, 300, true, SceneAntialiasing.BALANCED);
        subScene.setFill(Color.TRANSPARENT);
        subScene.setCamera(camera);

        return new Group(subScene);
    }
 
源代码6 项目: FXTutorials   文件: Tutorial.java
private Parent createContent() {
    Cube c = new Cube(1, Color.GREEN);
    c.setTranslateX(-1);
    c.setRotationAxis(Rotate.Y_AXIS);
    c.setRotate(45);

    Cube c2 = new Cube(1, Color.BLUE);
    c2.setTranslateX(1);
    c2.setRotationAxis(Rotate.Y_AXIS);
    c2.setRotate(45);

    Cube c3 = new Cube(1, Color.RED);
    c3.setRotationAxis(Rotate.Y_AXIS);
    c3.setRotate(45);

    camera = new PerspectiveCamera(true);
    translate = new Translate(0, 0, -10);
    rotate = new Rotate(0, new Point3D(0, 1, 0));
    camera.getTransforms().addAll(translate, rotate);

    PointLight light = new PointLight(Color.WHITE);
    light.setTranslateX(3);
    light.setTranslateZ(-5);

    TranslateTransition tt = new TranslateTransition(Duration.seconds(2), light);
    tt.setFromX(-3);
    tt.setToX(3);
    tt.setAutoReverse(true);
    tt.setCycleCount(Animation.INDEFINITE);

    AmbientLight globalLight = new AmbientLight(Color.WHITE.deriveColor(0, 1, 0.2, 1));


    worldRoot.getChildren().addAll(c, c2, c3, globalLight, light);

    SubScene subScene = new SubScene(worldRoot, 800, 600, true, SceneAntialiasing.BALANCED);
    subScene.setCamera(camera);

    tt.play();

    return new Group(new Rectangle(800, 600), subScene);
}
 
源代码7 项目: FXyzLib   文件: PolyLine3D.java
public PolyLine3D(List<Point3D> points, int width, Color color) {
    this.points = points;
    this.width = width;
    this.color = color;
    setDepthTest(DepthTest.ENABLE);        
    mesh  = new TriangleMesh();
    //add each point. For each point add another point shifted on Z axis by width
    //This extra point allows us to build triangles later
    for(Point3D point: points) {
        mesh.getPoints().addAll(point.x,point.y,point.z);
        mesh.getPoints().addAll(point.x,point.y,point.z+width);
    }
    //add dummy Texture Coordinate
    mesh.getTexCoords().addAll(0,0); 
    //Now generate trianglestrips for each line segment
    for(int i=2;i<points.size()*2;i+=2) {  //add each segment
        //Vertices wound counter-clockwise which is the default front face of any Triange
        //These triangles live on the frontside of the line facing the camera
        mesh.getFaces().addAll(i,0,i-2,0,i+1,0); //add primary face
        mesh.getFaces().addAll(i+1,0,i-2,0,i-1,0); //add secondary Width face
        //Add the same faces but wind them clockwise so that the color looks correct when camera is rotated
        //These triangles live on the backside of the line facing away from initial the camera
        mesh.getFaces().addAll(i+1,0,i-2,0,i,0); //add primary face
        mesh.getFaces().addAll(i-1,0,i-2,0,i+1,0); //add secondary Width face
    }
    //Need to add the mesh to a MeshView before adding to our 3D scene 
    meshView = new MeshView(mesh);
    meshView.setDrawMode(DrawMode.FILL);  //Fill so that the line shows width
    material = new PhongMaterial(color);
    material.setDiffuseColor(color);
    material.setSpecularColor(color);
    meshView.setMaterial(material); 
    //Make sure you Cull the Back so that no black shows through
    meshView.setCullFace(CullFace.BACK);

    //Add some ambient light so folks can see it
    AmbientLight light = new AmbientLight(Color.WHITE);
    light.getScope().add(meshView);
    getChildren().add(light);
    getChildren().add(meshView);           
}
 
源代码8 项目: FXyzLib   文件: ShapeContainer.java
@Override
public AmbientLight getSelfIlluminationLight() {
    return selfIllumination;
}
 
源代码9 项目: FXyzLib   文件: SphereSegment.java
/**
 * @param radius radius of the sphere segment
 * @param color The sphere segment color.
 * @param phimin The starting azimutal angle [rad], 0-2*pi.
 * @param phimax The ending azimutal angle [rad], 0-2*pi, phimax &gt;
 * phimin.
 * @param thetamin The starting polar angle [rad], -pi/2-pi/2.
 * @param thetamax The ending polar angle [rad], -pi/2-pi/2, thetamax &gt;
 * thetamin.
 * @param granularity The number of segments of curves approximations,
 * granulariy &gt; 2.
 * @param ambient Whether to have an ambient light or not
 * @param fill whether to show filled with the color param or as wire mesh
 */
public SphereSegment(double radius, Color color,
        double phimin, double phimax, double thetamin, double thetamax,
        int granularity, boolean ambient, boolean fill) {

    this.radius = radius;
    this.color = color;
    this.phimin = phimin;
    this.phimax = phimax;
    this.thetamin = thetamin;
    this.thetamax = thetamax;
    this.granularity = granularity;
    this.ambient = ambient;
    this.fill = fill;
    setDepthTest(DepthTest.ENABLE);

    mesh = new TriangleMesh();
    // Fill Points
    double phi = phimin;
    double theta;

    PhongMaterial maxPhong = new PhongMaterial();
    maxPhong.setSpecularColor(color);
    maxPhong.setDiffuseColor(color);

    for (int i = 0; i < granularity + 1; i++) {
        theta = thetamin;
        for (int j = 0; j < granularity + 1; j++) {
            Point3D p3D = new Point3D((float) (radius * Math.cos(theta) * Math.sin(phi)),
                    (float) (radius * Math.cos(theta) * Math.cos(phi)),
                    (float) (radius * Math.sin(theta)));
            mesh.getPoints().addAll(new Float(p3D.getX()), new Float(p3D.getY()), new Float(p3D.getZ()));
            theta += (thetamax - thetamin) / granularity;
        }
        phi += (phimax - phimin) / granularity;
    }

    //for now we'll just make an empty texCoordinate group
    mesh.getTexCoords().addAll(0, 0);
    //Add the faces "winding" the points generally counter clock wise
    for (int i = 0; i < granularity; i++) {
        int multiplier = (i * granularity) + i;
        //Up the Outside
        for (int j = multiplier; j < granularity + multiplier; j++) {
            mesh.getFaces().addAll(j, 0, j + 1, 0, j + granularity + 1, 0); //lower triangle
            mesh.getFaces().addAll(j + granularity + 1, 0, j + 1, 0, j + granularity + 2, 0); //upper triangle
        }
        //Down the Inside            
        for (int j = granularity + multiplier; j > multiplier; j--) {
            mesh.getFaces().addAll(j, 0, j - 1, 0, j + granularity + 1, 0); //lower triangle
            mesh.getFaces().addAll(j - 1, 0, j + granularity, 0, j + granularity + 1, 0); //upper triangle
        }
    }

    //Create a viewable MeshView to be added to the scene
    //To add a TriangleMesh to a 3D scene you need a MeshView container object
    meshView = new MeshView(mesh);
    //The MeshView allows you to control how the TriangleMesh is rendered
    if (fill) {
        meshView.setDrawMode(DrawMode.FILL);
    } else {
        meshView.setDrawMode(DrawMode.LINE); //show lines only by default
    }
    meshView.setCullFace(CullFace.BACK); //Removing culling to show back lines

    getChildren().add(meshView);
    meshView.setMaterial(maxPhong);
    if (ambient) {
        AmbientLight light = new AmbientLight(Color.WHITE);
        light.getScope().add(meshView);
        getChildren().add(light);
    }
}
 
源代码10 项目: FXyzLib   文件: AdvancedCamera.java
public AmbientLight getAmbientLight() {
    return ambientLight;
}
 
源代码11 项目: FXyzLib   文件: ShapeContainerBase.java
public AmbientLight getSelfIlluminationLight(); 
 类所在包
 同包方法