Пример #1
0
  @Override
  public void onStart(RenderingContext context) {
    scene = new Scene();
    camera = new PerspectiveCamera(50, context.getAspectRation(), 1, 1000);
    camera.getPosition().set(0, 150, 150);

    DirectionalLight light = new DirectionalLight(0xffffff);
    light.getPosition().set(0, 0, 1);
    scene.add(light);

    this.parentObject = new Object3D();
    this.parentObject.getPosition().setY(50);
    scene.add(this.parentObject);

    // Closed
    SplineCurve3 extrudeBend =
        new SplineCurve3(
            Arrays.asList(
                new Vector3(30, 12, 83),
                new Vector3(40, 20, 67),
                new Vector3(60, 40, 99),
                new Vector3(10, 60, 49),
                new Vector3(25, 80, 40)));

    SplineCurve3 pipeSpline =
        new SplineCurve3(
            Arrays.asList(
                new Vector3(0, 10, -10),
                new Vector3(10, 0, -10),
                new Vector3(20, 0, 0),
                new Vector3(30, 0, 10),
                new Vector3(30, 0, 20),
                new Vector3(20, 0, 30),
                new Vector3(10, 0, 30),
                new Vector3(0, 0, 30),
                new Vector3(-10, 10, 30),
                new Vector3(-10, 20, 30),
                new Vector3(0, 30, 30),
                new Vector3(10, 30, 30),
                new Vector3(20, 30, 15),
                new Vector3(10, 30, 10),
                new Vector3(0, 30, 10),
                new Vector3(-10, 20, 10),
                new Vector3(-10, 10, 10),
                new Vector3(0, 0, 10),
                new Vector3(10, -10, 10),
                new Vector3(20, -15, 10),
                new Vector3(30, -15, 10),
                new Vector3(40, -15, 10),
                new Vector3(50, -15, 10),
                new Vector3(60, 0, 10),
                new Vector3(70, 0, 0),
                new Vector3(80, 0, 0),
                new Vector3(90, 0, 0),
                new Vector3(100, 0, 0)));

    SplineCurve3Closed sampleClosedSpline =
        new SplineCurve3Closed(
            Arrays.asList(
                new Vector3(0, -40, -40),
                new Vector3(0, 40, -40),
                new Vector3(0, 140, -40),
                new Vector3(0, 40, 40),
                new Vector3(0, -40, 40)));

    //			List<Vector3> randomPoints = new ArrayList<Vector3>();
    //
    //			for (int i=0; i<10; i++)
    //				randomPoints.add(new Vector3((double)Math.random() * 200.0f, (double)Math.random() *
    // 200.0f, (double)Math.random() * 200.0f ));
    //
    //			SplineCurve3 randomSpline =  new SplineCurve3(randomPoints);

    SplineCurve3 randomSpline =
        new SplineCurve3(
            Arrays.asList(
                new Vector3(-40, -40, 0),
                new Vector3(40, -40, 0),
                new Vector3(140, -40, 0),
                new Vector3(40, 40, 0),
                new Vector3(-40, 40, 20)));

    //			ExtrudeGeometry.ExtrudeGeometryParameters extrudeParameters = new
    // ExtrudeGeometry.ExtrudeGeometryParameters();
    //			extrudeParameters.amount = 200;
    //			extrudeParameters.bevelEnabled = true;
    //			extrudeParameters.bevelSegments = 2;
    //			extrudeParameters.steps = 150;
    //			extrudeParameters.extrudePath = randomSpline;

    // CircleGeometry

    double circleRadius = 4.0;
    Shape circleShape = new Shape();
    circleShape.moveTo(0, circleRadius);
    circleShape.quadraticCurveTo(circleRadius, circleRadius, circleRadius, 0);
    circleShape.quadraticCurveTo(circleRadius, -circleRadius, 0, -circleRadius);
    circleShape.quadraticCurveTo(-circleRadius, -circleRadius, -circleRadius, 0);
    circleShape.quadraticCurveTo(-circleRadius, circleRadius, 0, circleRadius);

    double rectLength = 12.0;
    double rectWidth = 4.0;

    Shape rectShape = new Shape();

    rectShape.moveTo(-rectLength / 2, -rectWidth / 2);
    rectShape.lineTo(-rectLength / 2, rectWidth / 2);
    rectShape.lineTo(rectLength / 2, rectWidth / 2);
    rectShape.lineTo(rectLength / 2, -rectLength / 2);
    rectShape.lineTo(-rectLength / 2, -rectLength / 2);

    // Smiley

    Shape smileyShape = new Shape();
    smileyShape.moveTo(80, 40);
    smileyShape.arc(40, 40, 40, 0.0, Math.PI * 2.0, false);

    Path smileyEye1Path = new Path();
    smileyEye1Path.moveTo(35, 20);
    smileyEye1Path.arc(25, 20, 10, 0.0, Math.PI * 2.0, true);
    smileyShape.getHoles().add(smileyEye1Path);

    Path smileyEye2Path = new Path();
    smileyEye2Path.moveTo(65, 20);
    smileyEye2Path.arc(55, 20, 10, 0.0, Math.PI * 2.0, true);
    smileyShape.getHoles().add(smileyEye2Path);

    Path smileyMouthPath = new Path();

    smileyMouthPath.moveTo(20, 40);
    smileyMouthPath.quadraticCurveTo(40, 60, 60, 40);
    smileyMouthPath.bezierCurveTo(70, 45, 70, 50, 60, 60);
    smileyMouthPath.quadraticCurveTo(40, 80, 20, 60);
    smileyMouthPath.quadraticCurveTo(5, 50, 20, 40);

    smileyShape.getHoles().add(smileyMouthPath);

    List<Vector2> pts = new ArrayList<Vector2>();
    int starPoints = 5;
    double l;
    for (int i = 0; i < starPoints * 2; i++) {
      l = (Mathematics.isEven(i)) ? 5.0 : 10.0;
      double a = i / starPoints * Math.PI;

      pts.add(new Vector2(Math.cos(a) * l, Math.sin(a) * l));
    }

    Shape starShape = new Shape(pts);
    //			ExtrudeGeometry circle3d = starShape.extrude( extrudeParameters ); //circleShape rectShape
    // smileyShape starShape

    //			TubeGeometry tubeGeometry = new TubeGeometry((CurvePath) extrudeParameters.extrudePath,
    // 150, 4.0, 5, false, true);

    //			addGeometry( circle3d, new Color(0xff1111),
    //					-100f, 0, 0,
    //					0, 0, 0,
    //					1);

    //			addGeometry( tubeGeometry, new Color(0x00ff11),
    //					0, 0, 0,
    //					0, 0, 0,
    //					1);

    context.getRenderer().setClearColor(0xCCCCCC);
  }
Пример #2
0
  @Override
  public void onStart(RenderingContext context) {
    scene = new Scene();
    camera =
        new PerspectiveCamera(
            40, // fov
            context.getRenderer().getAbsoluteAspectRation(), // aspect
            1, // near
            10000 // far
            );

    camera.getPosition().set(700, 180, -500);

    scene.setFog(new Fog(0xfafafa, 1000, 10000));

    // CONTROLS

    //		controls = new TrackballControls( camera, getCanvas() );
    //		controls.getTarget().setZ( 150 );

    // LIGHTS

    DirectionalLight directionalLight = new DirectionalLight(0xffffff, 1.475);
    directionalLight.getPosition().set(100, 100, -100);
    scene.add(directionalLight);

    HemisphereLight hemiLight = new HemisphereLight(0xffffff, 0xffffff, 1.25);
    hemiLight.getColor().setHSL(0.6, 1.0, 0.75);
    hemiLight.getGroundColor().setHSL(0.1, 0.8, 0.7);
    hemiLight.getPosition().setY(500);
    scene.add(hemiLight);

    // SKYDOME

    ShaderMaterial skyMat = new ShaderMaterial(Resources.INSTANCE).setSide(Material.SIDE.BACK);

    skyMat.getShader().addUniform("topColor", new Uniform(Uniform.TYPE.C, new Color(0x0077ff)));
    skyMat.getShader().addUniform("bottomColor", new Uniform(Uniform.TYPE.C, new Color(0xffffff)));
    skyMat
        .getShader()
        .addUniform("topColor", new Uniform(Uniform.TYPE.C, hemiLight.getColor().clone()));
    skyMat.getShader().addUniform("offset", new Uniform(Uniform.TYPE.F, 400.0));
    skyMat.getShader().addUniform("exponent", new Uniform(Uniform.TYPE.F, 0.6));

    scene
        .getFog()
        .setColor(((Color) skyMat.getShader().getUniforms().get("bottomColor").getValue()).clone());

    SphereGeometry skyGeo = new SphereGeometry(4000, 32, 15);
    Mesh sky = new Mesh(skyGeo, skyMat);
    scene.add(sky);

    // RENDERER

    context.getRenderer().setClearColor(scene.getFog().getColor(), 1);
    context.getRenderer().setGammaInput(true);
    context.getRenderer().setGammaOutput(true);

    // MODEL

    //		new JsonLoader(model, new XHRLoader.ModelLoadHandler() {
    //
    //			@Override
    //			public void onModelLoaded(XHRLoader loader, AbstractGeometry geometry) {
    //				Mesh mesh = new Mesh( geometry, new MeshFaceMaterial(((JsonLoader)loader).getMaterials())
    // );
    //				mesh.getPosition().set( 0 );
    //				mesh.getScale().set( 100 );
    //				scene.add( mesh );
    //			}
    //		});

  }