mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +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:
@@ -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.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 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.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.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.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.List;
|
||||
@@ -48,7 +48,7 @@ public class Marker extends Group {
|
||||
* @param exitAngle The angle the arrow wil point from the marker.
|
||||
*/
|
||||
public void addArrows(MarkArrowFactory.RoundingSide roundingSide, double entryAngle,
|
||||
double exitAngle) {
|
||||
double exitAngle) {
|
||||
//Change Color.GRAY to this.colour to revert all gray arrows.
|
||||
enterArrows.add(
|
||||
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.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.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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user