mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added 3D window to GameView3D to begin adding assets to. Used it to refine all 3D assets implemented by ModelFactory and manually test that they work.
#implement #test
This commit is contained in:
@@ -36,13 +36,14 @@ import seng302.model.mark.Corner;
|
|||||||
import seng302.model.mark.Mark;
|
import seng302.model.mark.Mark;
|
||||||
import seng302.model.token.Token;
|
import seng302.model.token.Token;
|
||||||
import seng302.utilities.GeoUtility;
|
import seng302.utilities.GeoUtility;
|
||||||
import seng302.visualiser.fxObjects.AnnotationBox;
|
import seng302.visualiser.fxObjects.assets_2D.AnnotationBox;
|
||||||
import seng302.visualiser.fxObjects.BoatObject;
|
import seng302.visualiser.fxObjects.assets_2D.BoatObject;
|
||||||
import seng302.visualiser.fxObjects.CourseBoundary;
|
import seng302.visualiser.fxObjects.assets_2D.CourseBoundary;
|
||||||
import seng302.visualiser.fxObjects.Gate;
|
import seng302.visualiser.fxObjects.assets_2D.Gate;
|
||||||
import seng302.visualiser.fxObjects.MarkArrowFactory;
|
import seng302.visualiser.fxObjects.assets_2D.MarkArrowFactory;
|
||||||
import seng302.visualiser.fxObjects.Marker;
|
import seng302.visualiser.fxObjects.assets_2D.Marker;
|
||||||
import seng302.visualiser.fxObjects.VelocityPickup;
|
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||||
|
import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||||
import seng302.visualiser.map.Boundary;
|
import seng302.visualiser.map.Boundary;
|
||||||
import seng302.visualiser.map.CanvasMap;
|
import seng302.visualiser.map.CanvasMap;
|
||||||
|
|
||||||
@@ -460,7 +461,7 @@ public class GameView extends Pane {
|
|||||||
mapTokens = new ArrayList<>();
|
mapTokens = new ArrayList<>();
|
||||||
for (Token token : newTokens) {
|
for (Token token : newTokens) {
|
||||||
Point2D location = findScaledXY(token.getLat(), token.getLng());
|
Point2D location = findScaledXY(token.getLat(), token.getLng());
|
||||||
Node tokenObject = new VelocityPickup();
|
Node tokenObject = ModelFactory.importModel(ModelType.VELOCITY_COIN).getAssets();
|
||||||
tokenObject.setLayoutX(location.getX());
|
tokenObject.setLayoutX(location.getX());
|
||||||
tokenObject.setLayoutY(location.getY());
|
tokenObject.setLayoutY(location.getY());
|
||||||
mapTokens.add(tokenObject);
|
mapTokens.add(tokenObject);
|
||||||
|
|||||||
@@ -1,32 +1,121 @@
|
|||||||
package seng302.visualiser;
|
package seng302.visualiser;
|
||||||
|
|
||||||
import javafx.scene.Camera;
|
import javafx.geometry.Point3D;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.*;
|
||||||
import javafx.scene.PerspectiveCamera;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.SceneAntialiasing;
|
import javafx.scene.paint.PhongMaterial;
|
||||||
import javafx.scene.SubScene;
|
import javafx.scene.shape.Sphere;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
import javafx.scene.transform.Translate;
|
||||||
|
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
|
||||||
|
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||||
|
import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cir27 on 5/09/17.
|
* Collection of animated3D assets that displays a race.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GameView3D {
|
public class GameView3D {
|
||||||
|
|
||||||
|
private final double FOV = 60;
|
||||||
|
private final double DEFAULT_CAMERA_DEPTH = 100;
|
||||||
|
|
||||||
Group root3D;
|
Group root3D;
|
||||||
SubScene scene;
|
SubScene view;
|
||||||
Camera camera;
|
PerspectiveCamera camera;
|
||||||
Group gameObjects;
|
Group gameObjects;
|
||||||
|
|
||||||
public GameView3D () {
|
public GameView3D () {
|
||||||
camera = new PerspectiveCamera();
|
camera = new PerspectiveCamera(true);
|
||||||
|
camera.getTransforms().addAll(
|
||||||
|
new Translate(0,0, -DEFAULT_CAMERA_DEPTH)
|
||||||
|
);
|
||||||
|
camera.setFarClip(0);
|
||||||
|
camera.setFieldOfView(FOV);
|
||||||
gameObjects = new Group();
|
gameObjects = new Group();
|
||||||
root3D = new Group(camera, gameObjects);
|
root3D = new Group(camera, gameObjects);
|
||||||
scene = new SubScene(
|
view = new SubScene(
|
||||||
root3D, 750, 750, true, SceneAntialiasing.BALANCED
|
root3D, 1000, 1000, true, SceneAntialiasing.BALANCED
|
||||||
);
|
);
|
||||||
scene.setCamera(camera);
|
view.setCamera(camera);
|
||||||
|
Sphere s = new Sphere(1);
|
||||||
|
s.setMaterial(new PhongMaterial(Color.RED));
|
||||||
|
Sphere left = new Sphere(1);
|
||||||
|
left.setMaterial(new PhongMaterial(Color.LEMONCHIFFON));
|
||||||
|
left.getTransforms().add(new Translate(-Math.tan(Math.toRadians(FOV / 2)) * DEFAULT_CAMERA_DEPTH, 0, 0));
|
||||||
|
Sphere right = new Sphere(1);
|
||||||
|
right.setMaterial(new PhongMaterial(Color.ROSYBROWN));
|
||||||
|
right.getTransforms().add(new Translate(Math.tan(Math.toRadians(FOV / 2)) * DEFAULT_CAMERA_DEPTH, 0, 0));
|
||||||
|
Sphere top = new Sphere(1);
|
||||||
|
top.setMaterial(new PhongMaterial(Color.TEAL));
|
||||||
|
top.getTransforms().add(new Translate(0,-Math.tan(Math.toRadians(FOV / 2)) * DEFAULT_CAMERA_DEPTH, 0));
|
||||||
|
Sphere bottom = new Sphere(1);
|
||||||
|
bottom.setMaterial(new PhongMaterial(Color.BLANCHEDALMOND));
|
||||||
|
bottom.getTransforms().add(new Translate(0, Math.tan(Math.toRadians(FOV / 2)) * DEFAULT_CAMERA_DEPTH, 0));
|
||||||
|
|
||||||
|
Node boat = ModelFactory.boatGameView(BoatMeshType.DINGHY, Color.BLUE).getAssets();
|
||||||
|
Node boat2 = ModelFactory.boatGameView(BoatMeshType.DINGHY, Color.BROWN).getAssets();
|
||||||
|
boat2.getTransforms().add(new Translate(0,20, 0));
|
||||||
|
Node boat3 = ModelFactory.boatGameView(BoatMeshType.DINGHY, Color.RED).getAssets();
|
||||||
|
boat3.getTransforms().add(new Translate(0,-20, 0));
|
||||||
|
|
||||||
|
Node sMarker = ModelFactory.importModel(ModelType.START_MARKER).getAssets();
|
||||||
|
sMarker.getTransforms().add(0, new Translate(30, 30, 0));
|
||||||
|
|
||||||
|
Node fMarker = ModelFactory.importModel(ModelType.FINISH_MARKER).getAssets();
|
||||||
|
fMarker.getTransforms().add(0, new Translate(30, -30, 0));
|
||||||
|
|
||||||
|
Node marker = ModelFactory.importModel(ModelType.PLAIN_MARKER).getAssets();
|
||||||
|
marker.getTransforms().add(0, new Translate(30, 0, 0));
|
||||||
|
|
||||||
|
Node coin = ModelFactory.importModel(ModelType.VELOCITY_COIN).getAssets();
|
||||||
|
coin.setTranslateX(coin.getTranslateX() - 30);
|
||||||
|
|
||||||
|
gameObjects.getChildren().addAll(s, left, right, top, bottom, boat, boat2, boat3, sMarker, fMarker, marker, coin);
|
||||||
|
view.sceneProperty().addListener((obs, old, scene) -> {
|
||||||
|
if (scene!=null)
|
||||||
|
makeMovement(scene);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubScene getScene () {
|
public void makeMovement(Scene s) {
|
||||||
return scene;
|
s.setOnKeyPressed(event -> {
|
||||||
|
switch (event.getCode()) {
|
||||||
|
case UP:
|
||||||
|
camera.getTransforms().addAll(new Rotate(0.5, new Point3D(1,0,0)));
|
||||||
|
break;
|
||||||
|
case DOWN:
|
||||||
|
camera.getTransforms().addAll(new Rotate(-0.5, new Point3D(1,0,0)));
|
||||||
|
break;
|
||||||
|
case LEFT:
|
||||||
|
camera.getTransforms().addAll(new Rotate(-0.5, new Point3D(0,1,0)));
|
||||||
|
break;
|
||||||
|
case RIGHT:
|
||||||
|
camera.getTransforms().addAll(new Rotate(0.5, new Point3D(0,1,0)));
|
||||||
|
break;
|
||||||
|
case SPACE:
|
||||||
|
camera.getTransforms().addAll(new Translate(0, 0, 0.75));
|
||||||
|
break;
|
||||||
|
case Z:
|
||||||
|
camera.getTransforms().addAll(new Translate(0, 0, -0.75));
|
||||||
|
break;
|
||||||
|
case W:
|
||||||
|
camera.getTransforms().addAll(new Translate(0, 1, 0));
|
||||||
|
break;
|
||||||
|
case S:
|
||||||
|
camera.getTransforms().addAll(new Translate(0, -1, 0));
|
||||||
|
break;
|
||||||
|
case A:
|
||||||
|
camera.getTransforms().addAll(new Translate(-1, 0, 0));
|
||||||
|
break;
|
||||||
|
case D:
|
||||||
|
camera.getTransforms().addAll(new Translate(1, 0, 0));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getAssets () {
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ import seng302.visualiser.controllers.annotations.Annotation;
|
|||||||
import seng302.visualiser.controllers.annotations.ImportantAnnotationController;
|
import seng302.visualiser.controllers.annotations.ImportantAnnotationController;
|
||||||
import seng302.visualiser.controllers.annotations.ImportantAnnotationDelegate;
|
import seng302.visualiser.controllers.annotations.ImportantAnnotationDelegate;
|
||||||
import seng302.visualiser.controllers.annotations.ImportantAnnotationsState;
|
import seng302.visualiser.controllers.annotations.ImportantAnnotationsState;
|
||||||
import seng302.visualiser.fxObjects.BoatObject;
|
import seng302.visualiser.fxObjects.assets_2D.BoatObject;
|
||||||
import seng302.visualiser.fxObjects.WindArrow;
|
import seng302.visualiser.fxObjects.assets_2D.WindArrow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller class that manages the display of a race
|
* Controller class that manages the display of a race
|
||||||
|
|||||||
@@ -1,177 +0,0 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
|
||||||
|
|
||||||
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
|
||||||
import javafx.animation.AnimationTimer;
|
|
||||||
import javafx.geometry.Point3D;
|
|
||||||
import javafx.scene.Group;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.paint.PhongMaterial;
|
|
||||||
import javafx.scene.shape.MeshView;
|
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
import javafx.scene.transform.Scale;
|
|
||||||
import seng302.visualiser.test3d;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory class for creating 3D models of boats.
|
|
||||||
*/
|
|
||||||
public class ModelFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enum for boat meshes. Enum values should be of the form :
|
|
||||||
* ENUM_VALUE (hull file, mast file, y offset of mast CoR from origin, sail file, y offset of sail CoR from origin)
|
|
||||||
*/
|
|
||||||
public enum BoatMesh {
|
|
||||||
|
|
||||||
DINGHY ("dinghy_hull.stl", "dinghy_mast.stl", 0, "dinghy_sail.stl", -1.36653);
|
|
||||||
|
|
||||||
private final String hullFile, mastFile, sailFile;
|
|
||||||
private final double mastOffset, sailOffset;
|
|
||||||
|
|
||||||
BoatMesh (String hullFile, String mastFile, double mastOffset, String sailFile, double sailOffset) {
|
|
||||||
this.hullFile = hullFile;
|
|
||||||
this.mastFile = mastFile;
|
|
||||||
this.mastOffset = mastOffset;
|
|
||||||
this.sailFile = sailFile;
|
|
||||||
this.sailOffset = sailOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Container class for a group of 3d objects representing a boat and it's animation.
|
|
||||||
*/
|
|
||||||
public class BoatModel {
|
|
||||||
|
|
||||||
private AnimationTimer animationTimer;
|
|
||||||
private Group assets;
|
|
||||||
private BoatMesh meshType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores a model and it's optional animation.
|
|
||||||
* @param boatAssets The group with 3d assets for the boat.
|
|
||||||
* @param animation Animation, can be null.
|
|
||||||
*/
|
|
||||||
private BoatModel(Group boatAssets, AnimationTimer animation, BoatMesh meshType) {
|
|
||||||
this.assets = boatAssets;
|
|
||||||
this.animationTimer = animation;
|
|
||||||
this.meshType = meshType;
|
|
||||||
if (animation != null) {
|
|
||||||
animation.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates the sail of this model by the given amount.
|
|
||||||
* @param degrees The rotation of the sail in degrees
|
|
||||||
*/
|
|
||||||
public void RotateSail(double degrees) {
|
|
||||||
MeshView mast = (MeshView) assets.getChildren().get(1);
|
|
||||||
MeshView sail = (MeshView) assets.getChildren().get(2);
|
|
||||||
mast.getTransforms().setAll(
|
|
||||||
new Rotate(degrees, 0, meshType.mastOffset, 0, new Point3D(0, 0, 1))
|
|
||||||
);
|
|
||||||
sail.getTransforms().setAll(
|
|
||||||
new Rotate(degrees, 0, meshType.sailOffset, 0, new Point3D(0, 0, 1))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Group getAssets() {
|
|
||||||
return this.assets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the colour of the model in this class.
|
|
||||||
* @param newColour the new colour for the boat.
|
|
||||||
*/
|
|
||||||
public void changeColour(Color newColour) {
|
|
||||||
changeColourChild(0, newColour);
|
|
||||||
changeColourChild(1, newColour);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeColourChild(int index, Color newColour) {
|
|
||||||
MeshView meshView = getMeshViewChild(index);
|
|
||||||
meshView.setMaterial(new PhongMaterial(newColour));
|
|
||||||
}
|
|
||||||
|
|
||||||
private MeshView getMeshViewChild(int index) {
|
|
||||||
return (MeshView) assets.getChildren().get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setAnimation(AnimationTimer animation) {
|
|
||||||
animationTimer = animation;
|
|
||||||
if (animation != null) {
|
|
||||||
animation.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the animation of this model.
|
|
||||||
*/
|
|
||||||
public void stopAnimation() {
|
|
||||||
if (animationTimer != null) {
|
|
||||||
animationTimer.stop();
|
|
||||||
animationTimer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoatModel getIconView(BoatMesh boatType, Color primaryColour) {
|
|
||||||
Group boatAssets = new Group();
|
|
||||||
MeshView hull = importFile(boatType.hullFile);
|
|
||||||
hull.setMaterial(new PhongMaterial(primaryColour));
|
|
||||||
MeshView mast = importFile(boatType.mastFile);
|
|
||||||
mast.setMaterial(new PhongMaterial(primaryColour));
|
|
||||||
MeshView sail = importFile(boatType.hullFile);
|
|
||||||
sail.setMaterial(new PhongMaterial(Color.WHITE));
|
|
||||||
boatAssets.getChildren().addAll(hull, mast, sail);
|
|
||||||
boatAssets.getTransforms().addAll(
|
|
||||||
new Scale(20, 20, 20),
|
|
||||||
new Rotate(90, new Point3D(0,0,1)),
|
|
||||||
new Rotate(90, new Point3D(0, 1, 0))
|
|
||||||
);
|
|
||||||
return new BoatModel(boatAssets, null, boatType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoatModel getRotatingView(BoatMesh boatType, Color primaryColour) {
|
|
||||||
Group boatAssets = new Group();
|
|
||||||
MeshView hull = importFile(boatType.hullFile);
|
|
||||||
hull.setMaterial(new PhongMaterial(primaryColour));
|
|
||||||
MeshView mast = importFile(boatType.mastFile);
|
|
||||||
mast.setMaterial(new PhongMaterial(primaryColour));
|
|
||||||
MeshView sail = importFile(boatType.hullFile);
|
|
||||||
sail.setMaterial(new PhongMaterial(Color.WHITE));
|
|
||||||
boatAssets.getChildren().addAll(hull, mast, sail);
|
|
||||||
boatAssets.getTransforms().addAll(
|
|
||||||
new Scale(40, 40, 40),
|
|
||||||
new Rotate(90, new Point3D(0,0,1)),
|
|
||||||
new Rotate(90, new Point3D(0, 1, 0)),
|
|
||||||
new Rotate(0, new Point3D(1,1,1))
|
|
||||||
);
|
|
||||||
// TODO: 7/09/17 This seems like it will never be garbage claimed. Might have to call BoatModel.stopAnimation();
|
|
||||||
return new BoatModel(boatAssets, new AnimationTimer() {
|
|
||||||
|
|
||||||
private double rotation = 0;
|
|
||||||
private final Group group = boatAssets;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(long now) {
|
|
||||||
rotation += 0.5;
|
|
||||||
((Rotate) group.getTransforms().get(3)).setAngle(rotation);
|
|
||||||
}
|
|
||||||
}, boatType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoatModel getGameView(BoatMesh boatType, Color primaryColour) {
|
|
||||||
BoatModel model = getIconView(boatType, primaryColour);
|
|
||||||
model.getAssets().getTransforms().setAll(
|
|
||||||
new Scale(20, 20, 20),
|
|
||||||
new Rotate(90, new Point3D(0,0,1))
|
|
||||||
);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MeshView importFile(String fileName) {
|
|
||||||
StlMeshImporter importer = new StlMeshImporter();
|
|
||||||
importer.read(test3d.class.getResource("/meshes/" + fileName).toString());
|
|
||||||
return new MeshView(importer.getImport());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
|
||||||
|
|
||||||
import javafx.animation.AnimationTimer;
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.geometry.Point3D;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.paint.PhongMaterial;
|
|
||||||
import javafx.scene.shape.Cylinder;
|
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by cir27 on 3/09/17.
|
|
||||||
*/
|
|
||||||
public class VelocityPickup extends Cylinder {
|
|
||||||
|
|
||||||
public double rotation = 0;
|
|
||||||
public Rotate timerRotation = new Rotate(0, new Point3D(1,1,1));
|
|
||||||
|
|
||||||
public VelocityPickup () {
|
|
||||||
// StlMeshImporter importer = new StlMeshImporter();
|
|
||||||
// importer.read(getClass().getResource("/velocity_pickup.stl").toString());
|
|
||||||
// this.setMesh(importer.getImport());
|
|
||||||
this.setRadius(10);
|
|
||||||
this.setHeight(10);
|
|
||||||
this.setMaterial(new PhongMaterial(Color.YELLOW));
|
|
||||||
// this.getTransforms().add(new Scale(30,30,30));
|
|
||||||
// this.getTransforms().add(new Rotate(30, new Point3D(1,0, 0)));
|
|
||||||
// this.getTransforms().add(new Rotate(90, new Point3D(0,1, 0)));
|
|
||||||
this.getTransforms().add(timerRotation);
|
|
||||||
AnimationTimer at = new AnimationTimer() {
|
|
||||||
@Override
|
|
||||||
public void handle(long now) {
|
|
||||||
Platform.runLater(() -> timerRotation.setAngle(rotation++));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
at.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.shape.Line;
|
import javafx.scene.shape.Line;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -48,7 +48,7 @@ public class Marker extends Group {
|
|||||||
* @param exitAngle The angle the arrow wil point from the marker.
|
* @param exitAngle The angle the arrow wil point from the marker.
|
||||||
*/
|
*/
|
||||||
public void addArrows(MarkArrowFactory.RoundingSide roundingSide, double entryAngle,
|
public void addArrows(MarkArrowFactory.RoundingSide roundingSide, double entryAngle,
|
||||||
double exitAngle) {
|
double exitAngle) {
|
||||||
//Change Color.GRAY to this.colour to revert all gray arrows.
|
//Change Color.GRAY to this.colour to revert all gray arrows.
|
||||||
enterArrows.add(
|
enterArrows.add(
|
||||||
MarkArrowFactory.constructEntryArrow(roundingSide, entryAngle, exitAngle, Color.GRAY)
|
MarkArrowFactory.constructEntryArrow(roundingSide, entryAngle, exitAngle, Color.GRAY)
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.CacheHint;
|
import javafx.scene.CacheHint;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualiser.fxObjects;
|
package seng302.visualiser.fxObjects.assets_2D;
|
||||||
|
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.shape.Polyline;
|
import javafx.scene.shape.Polyline;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package seng302.visualiser.fxObjects.assets_3D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for boat meshes. Enum values should be of the form :
|
||||||
|
* ENUM_VALUE (hull file, mast file, X offset of mast CoR from origin, sail file, X offset of sail CoR from origin)
|
||||||
|
* Files must be valid .stl files.
|
||||||
|
*/
|
||||||
|
public enum BoatMeshType {
|
||||||
|
|
||||||
|
DINGHY ("dinghy_hull.stl", "dinghy_mast.stl", 0, "dinghy_sail.stl", -1.36653);
|
||||||
|
|
||||||
|
final String hullFile, mastFile, sailFile;
|
||||||
|
final double mastOffset, sailOffset;
|
||||||
|
|
||||||
|
BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, double sailOffset) {
|
||||||
|
this.hullFile = hullFile;
|
||||||
|
this.mastFile = mastFile;
|
||||||
|
this.mastOffset = mastOffset;
|
||||||
|
this.sailFile = sailFile;
|
||||||
|
this.sailOffset = sailOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package seng302.visualiser.fxObjects.assets_3D;
|
||||||
|
|
||||||
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.geometry.Point3D;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.paint.PhongMaterial;
|
||||||
|
import javafx.scene.shape.MeshView;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container class for a group of 3d objects representing a boat and it's animation.
|
||||||
|
*/
|
||||||
|
public class BoatModel extends Model {
|
||||||
|
|
||||||
|
private static final int HULL_INDEX = 0;
|
||||||
|
private static final int MAST_INDEX = 1;
|
||||||
|
private static final int SAIL_INDEX = 2;
|
||||||
|
|
||||||
|
private BoatMeshType meshType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a model and it's optional animation.
|
||||||
|
* @param boatAssets The group with 3d assets for the boat.
|
||||||
|
* @param animation Animation, can be null.
|
||||||
|
*/
|
||||||
|
BoatModel(Group boatAssets, AnimationTimer animation, BoatMeshType meshType) {
|
||||||
|
super(boatAssets, animation);
|
||||||
|
this.meshType = meshType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the sail of this model by the given amount.
|
||||||
|
* @param degrees The rotation of the sail in degrees
|
||||||
|
*/
|
||||||
|
public void RotateSail(double degrees) {
|
||||||
|
MeshView mast = getMeshViewChild(MAST_INDEX);
|
||||||
|
MeshView sail = getMeshViewChild(SAIL_INDEX);
|
||||||
|
mast.getTransforms().setAll(
|
||||||
|
new Rotate(degrees, meshType.mastOffset, 0,0, new Point3D(0, 0, 1))
|
||||||
|
);
|
||||||
|
sail.getTransforms().setAll(
|
||||||
|
new Rotate(degrees, meshType.sailOffset, 0,0, new Point3D(0, 0, 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideSail() {
|
||||||
|
getMeshViewChild(SAIL_INDEX).setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showSail() {
|
||||||
|
getMeshViewChild(SAIL_INDEX).setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the colour of the model in this class.
|
||||||
|
* @param newColour the new colour for the boat.
|
||||||
|
*/
|
||||||
|
public void changeColour(Color newColour) {
|
||||||
|
changeColourChild(HULL_INDEX, newColour);
|
||||||
|
changeColourChild(SAIL_INDEX, newColour);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeColourChild(int index, Color newColour) {
|
||||||
|
MeshView meshView = getMeshViewChild(index);
|
||||||
|
meshView.setMaterial(new PhongMaterial(newColour));
|
||||||
|
}
|
||||||
|
|
||||||
|
private MeshView getMeshViewChild(int index) {
|
||||||
|
return (MeshView) assets.getChildren().get(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package seng302.visualiser.fxObjects.assets_3D;
|
||||||
|
|
||||||
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by CJIRWIN on 7/09/2017.
|
||||||
|
*/
|
||||||
|
public class Model {
|
||||||
|
|
||||||
|
AnimationTimer animationTimer;
|
||||||
|
Group assets;
|
||||||
|
|
||||||
|
Model (Group assets, AnimationTimer animation) {
|
||||||
|
this.assets = assets;
|
||||||
|
this.animationTimer = animation;
|
||||||
|
if (animation != null) {
|
||||||
|
animation.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAnimation(AnimationTimer animation) {
|
||||||
|
animationTimer = animation;
|
||||||
|
if (animation != null) {
|
||||||
|
animation.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the animation of this model.
|
||||||
|
*/
|
||||||
|
public void stopAnimation() {
|
||||||
|
if (animationTimer != null) {
|
||||||
|
animationTimer.stop();
|
||||||
|
animationTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group getAssets() {
|
||||||
|
return this.assets;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package seng302.visualiser.fxObjects.assets_3D;
|
||||||
|
|
||||||
|
import com.interactivemesh.jfx.importer.col.ColModelImporter;
|
||||||
|
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
||||||
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.geometry.Point3D;
|
||||||
|
import javafx.scene.AmbientLight;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.paint.PhongMaterial;
|
||||||
|
import javafx.scene.shape.MeshView;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
import javafx.scene.transform.Scale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory class for creating 3D models of boats.
|
||||||
|
*/
|
||||||
|
public class ModelFactory {
|
||||||
|
|
||||||
|
public static BoatModel boatIconView(BoatMeshType boatType, Color primaryColour) {
|
||||||
|
Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour);
|
||||||
|
boatAssets.getTransforms().addAll(
|
||||||
|
new Scale(20, 20, 20),
|
||||||
|
new Rotate(90, new Point3D(0,0,1)),
|
||||||
|
new Rotate(90, new Point3D(0, 1, 0))
|
||||||
|
);
|
||||||
|
boatAssets.getChildren().add(new AmbientLight(new Color(1, 1, 1, 0.01)));
|
||||||
|
return new BoatModel(boatAssets, null, boatType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoatModel boatRotatingView(BoatMeshType boatType, Color primaryColour) {
|
||||||
|
Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour);
|
||||||
|
boatAssets.getTransforms().addAll(
|
||||||
|
new Scale(40, 40, 40),
|
||||||
|
new Rotate(90, new Point3D(0,0,1)),
|
||||||
|
new Rotate(90, new Point3D(0, 1, 0)),
|
||||||
|
new Rotate(0, new Point3D(1,1,1))
|
||||||
|
);
|
||||||
|
// TODO: 7/09/17 This seems like it will never be garbage claimed. Might have to call BoatModel.stopAnimation();
|
||||||
|
return new BoatModel(boatAssets, new AnimationTimer() {
|
||||||
|
|
||||||
|
private double rotation = 0;
|
||||||
|
private final Group group = boatAssets;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
rotation += 0.5;
|
||||||
|
((Rotate) group.getTransforms().get(3)).setAngle(rotation);
|
||||||
|
}
|
||||||
|
}, boatType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoatModel boatGameView(BoatMeshType boatType, Color primaryColour) {
|
||||||
|
Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour);
|
||||||
|
boatAssets.getTransforms().setAll(
|
||||||
|
new Scale(0.5, 0.5, 0.5)
|
||||||
|
);
|
||||||
|
return new BoatModel(boatAssets, null, boatType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Group getUnmodifiedBoatModel(BoatMeshType boatType, Color primaryColour) {
|
||||||
|
Group boatAssets = new Group();
|
||||||
|
MeshView hull = importFile(boatType.hullFile);
|
||||||
|
hull.setMaterial(new PhongMaterial(primaryColour));
|
||||||
|
MeshView mast = importFile(boatType.mastFile);
|
||||||
|
mast.setMaterial(new PhongMaterial(primaryColour));
|
||||||
|
MeshView sail = importFile(boatType.sailFile);
|
||||||
|
sail.setMaterial(new PhongMaterial(Color.WHITE));
|
||||||
|
boatAssets.getChildren().addAll(hull, mast, sail);
|
||||||
|
return boatAssets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MeshView importFile(String fileName) {
|
||||||
|
StlMeshImporter importer = new StlMeshImporter();
|
||||||
|
importer.read(ModelFactory.class.getResource("/meshes/" + fileName));
|
||||||
|
return new MeshView(importer.getImport());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Model importModel(ModelType tokenType) {
|
||||||
|
ColModelImporter importer = new ColModelImporter();
|
||||||
|
importer.read(ModelFactory.class.getResource("/meshes/" + tokenType.filename));
|
||||||
|
Group model = new Group(importer.getImport());
|
||||||
|
AnimationTimer animationTimer;
|
||||||
|
switch (tokenType) {
|
||||||
|
case VELOCITY_COIN:
|
||||||
|
model.setRotationAxis(new Point3D(1,0,0));
|
||||||
|
model.setRotate(90);
|
||||||
|
model.setTranslateX(0.2);
|
||||||
|
model.setTranslateY(1);
|
||||||
|
model.getTransforms().add(new Rotate(0 ,new Point3D(0,1,0)));
|
||||||
|
animationTimer = new AnimationTimer() {
|
||||||
|
|
||||||
|
private double rotation = 0;
|
||||||
|
private Group group = model;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
rotation += 0.5;
|
||||||
|
((Rotate) group.getTransforms().get(0)).setAngle(rotation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case FINISH_MARKER:
|
||||||
|
case PLAIN_MARKER:
|
||||||
|
case START_MARKER:
|
||||||
|
model.getTransforms().add(new Rotate(90, new Point3D(1, 0, 0)));
|
||||||
|
default:
|
||||||
|
animationTimer = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new Model(model, animationTimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package seng302.visualiser.fxObjects.assets_3D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for models. Values should be the name of the file and files should be .dae files with texture
|
||||||
|
* information included.
|
||||||
|
*/
|
||||||
|
public enum ModelType {
|
||||||
|
|
||||||
|
VELOCITY_COIN ("velocity_pickup.dae"),
|
||||||
|
FINISH_MARKER ("finish_marker.dae"),
|
||||||
|
START_MARKER ("start_marker.dae"),
|
||||||
|
PLAIN_MARKER ("plain_marker.dae");
|
||||||
|
|
||||||
|
final String filename;
|
||||||
|
|
||||||
|
ModelType(String filename) {
|
||||||
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -22,81 +22,87 @@ import javafx.stage.Stage;
|
|||||||
*/
|
*/
|
||||||
public class test3d extends Application {
|
public class test3d extends Application {
|
||||||
|
|
||||||
Group root3D;
|
Group root = new Group();
|
||||||
Scene scene;
|
Scene scene;
|
||||||
Camera camera;
|
|
||||||
Group gameObjects;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
camera = new PerspectiveCamera();
|
// camera = new PerspectiveCamera();
|
||||||
gameObjects = new Group();
|
// gameObjects = new Group();
|
||||||
root3D = new Group(camera, gameObjects);
|
// root3D = new Group(camera, gameObjects);
|
||||||
scene = new Scene(
|
scene = new Scene(
|
||||||
root3D, 750, 750, true, SceneAntialiasing.BALANCED
|
root, 1000, 1000, true, SceneAntialiasing.BALANCED
|
||||||
);
|
);
|
||||||
scene.setCamera(camera);
|
gameView3DTest();
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
// scene.setCamera(camera);
|
||||||
StlMeshImporter importer = new StlMeshImporter();
|
// primaryStage.setScene(scene);
|
||||||
importer.read(test3d.class.getResource("/meshes/dinghy_hull.stl").toString());
|
// primaryStage.show();
|
||||||
MeshView boat = new MeshView(importer.getImport());
|
|
||||||
boat.setMaterial(new PhongMaterial(Color.GREENYELLOW));
|
|
||||||
|
|
||||||
importer = new StlMeshImporter();
|
|
||||||
importer.read(getClass().getResource("/meshes/dinghy_mast.stl").toString());
|
|
||||||
MeshView mast = new MeshView(importer.getImport());
|
|
||||||
mast.setMaterial(new PhongMaterial(Color.GREENYELLOW));
|
|
||||||
|
|
||||||
importer = new StlMeshImporter();
|
|
||||||
importer.read(getClass().getResource("/meshes/dinghy_sail.stl").toString());
|
|
||||||
MeshView sail = new MeshView(importer.getImport());
|
|
||||||
sail.setMaterial(new PhongMaterial(Color.LIGHTGREY));
|
|
||||||
|
|
||||||
gameObjects.getChildren().addAll(boat, mast, sail);
|
|
||||||
|
|
||||||
gameObjects.getTransforms().add(new Scale(25, 25,25));
|
|
||||||
gameObjects.getTransforms().add(new Translate(15, 20,0));
|
|
||||||
gameObjects.getTransforms().addAll(
|
|
||||||
new Rotate(90, new Point3D(0,0,1)),
|
|
||||||
new Rotate(90, new Point3D(0, 1, 0))
|
|
||||||
);
|
|
||||||
|
|
||||||
// PointLight light = new PointLight();
|
|
||||||
// light.setLightOn(true);
|
|
||||||
// light.getTransforms().add(new Translate(15, 20, 0));
|
|
||||||
//
|
//
|
||||||
// PointLight light2 = new PointLight();
|
// StlMeshImporter importer = new StlMeshImporter();
|
||||||
// light2.setLightOn(true);
|
// importer.read(test3d.class.getResource("/meshes/dinghy_hull.stl").toString());
|
||||||
// light2.getTransforms().add(new Translate(30, 40, 0));
|
// MeshView boat = new MeshView(importer.getImport());
|
||||||
|
// boat.setMaterial(new PhongMaterial(Color.GREENYELLOW));
|
||||||
|
//
|
||||||
|
// importer = new StlMeshImporter();
|
||||||
|
// importer.read(getClass().getResource("/meshes/dinghy_mast.stl").toString());
|
||||||
|
// MeshView mast = new MeshView(importer.getImport());
|
||||||
|
// mast.setMaterial(new PhongMaterial(Color.GREENYELLOW));
|
||||||
|
//
|
||||||
|
// importer = new StlMeshImporter();
|
||||||
|
// importer.read(getClass().getResource("/meshes/dinghy_sail.stl").toString());
|
||||||
|
// MeshView sail = new MeshView(importer.getImport());
|
||||||
|
// sail.setMaterial(new PhongMaterial(Color.LIGHTGREY));
|
||||||
|
//
|
||||||
|
// gameObjects.getChildren().addAll(boat, mast, sail);
|
||||||
|
//
|
||||||
|
// gameObjects.getTransforms().add(new Scale(25, 25,25));
|
||||||
|
// gameObjects.getTransforms().add(new Translate(15, 20,0));
|
||||||
|
// gameObjects.getTransforms().addAll(
|
||||||
|
// new Rotate(90, new Point3D(0,0,1)),
|
||||||
|
// new Rotate(90, new Point3D(0, 1, 0))
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
//// PointLight light = new PointLight();
|
||||||
|
//// light.setLightOn(true);
|
||||||
|
//// light.getTransforms().add(new Translate(15, 20, 0));
|
||||||
|
////
|
||||||
|
//// PointLight light2 = new PointLight();
|
||||||
|
//// light2.setLightOn(true);
|
||||||
|
//// light2.getTransforms().add(new Translate(30, 40, 0));
|
||||||
|
//
|
||||||
|
//// root3D.getChildren().addAll(light);
|
||||||
|
//
|
||||||
|
// scene.setOnKeyPressed(event -> {
|
||||||
|
// switch (event.getCode()) {
|
||||||
|
// case UP:
|
||||||
|
// gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,0,1)));
|
||||||
|
// break;
|
||||||
|
// case DOWN:
|
||||||
|
// gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,0,1)));
|
||||||
|
// break;
|
||||||
|
// case LEFT:
|
||||||
|
// gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,1,0)));
|
||||||
|
// break;
|
||||||
|
// case RIGHT:
|
||||||
|
// gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,1,0)));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// AnimationTimer animationTimer = new AnimationTimer() {
|
||||||
|
// @Override
|
||||||
|
// public void handle(long now) {
|
||||||
|
// sail.getTransforms().add(new Rotate(0.5, 0, -1.36653, 0, new Point3D(0, 0, 1)));
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
//// animationTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
// root3D.getChildren().addAll(light);
|
private void gameView3DTest() {
|
||||||
|
GameView3D gameView3D = new GameView3D();
|
||||||
scene.setOnKeyPressed(event -> {
|
root.getChildren().add(gameView3D.getAssets());
|
||||||
switch (event.getCode()) {
|
|
||||||
case UP:
|
|
||||||
gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,0,1)));
|
|
||||||
break;
|
|
||||||
case DOWN:
|
|
||||||
gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,0,1)));
|
|
||||||
break;
|
|
||||||
case LEFT:
|
|
||||||
gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,1,0)));
|
|
||||||
break;
|
|
||||||
case RIGHT:
|
|
||||||
gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,1,0)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AnimationTimer animationTimer = new AnimationTimer() {
|
|
||||||
@Override
|
|
||||||
public void handle(long now) {
|
|
||||||
sail.getTransforms().add(new Rotate(0.5, 0, -1.36653, 0, new Point3D(0, 0, 1)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// animationTimer.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user