Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truck model #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/main/java/com/groep15/amazonsim/models/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.groep15.amazonsim.models;

import com.groep15.amazonsim.ai.ActionIdle;
import com.groep15.amazonsim.ai.IWorldAction;
import com.groep15.amazonsim.ai.IWorldActor;

public class Truck extends Object3D implements IWorldActor {
private IWorldAction action;
private boolean changedFromAction;

public Truck(World world) {
super(world);

this.passable = true;
this.action = new ActionIdle();
this.changedFromAction = this.action.onActionStart(this);
}

@Override
public boolean update() {
if (this.action.progress(this) || changedFromAction) {
changedFromAction = false;
return true;
}

return false;
}

@Override
public double getSpeed() {
return 0.25;
}

@Override
public void setAction(IWorldAction action) {
this.changedFromAction |= this.action.onActionDone(this);
this.action = action;
this.changedFromAction |= this.action.onActionStart(this);
}

@Override
public IWorldAction getAction() {
return this.action;
}

}
1 change: 1 addition & 0 deletions src/main/resources/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script src="js/SocketManager.js"></script>
<script src="js/WorldObject.js"></script>
<script src="js/World.js"></script>
<script src="js/loaders/ObjectLoader.js"></script>

<script>
window.addEventListener(
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/client/js/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ class World {
// TODO: Load this from the server instead.
//let floor = new Floor(this, Utility.MakeWorldObjectJSON("fake-uuid-01", [ 15, 0, 15 ], [ Math.PI / 2.0, 0, 0 ]));
let light = new AmbientLight(this, Utility.MakeWorldObjectJSON("fake-uuid-02", [ 0, 0, 0 ], [ 0, 0, 0 ], { intensity: 4, color: 0x404040 }));
//let truck = new Truck(this, Utility.MakeWorldObjectJSON("fake-uuid-03", [0, 0, 0], [0, 0, 0], ));

//this.addObject(truck);

//this.addObject(floor);
this.addObject(light);


// Render loop
this.frameCount = 0;
this.animate = () => {
Expand All @@ -83,6 +85,7 @@ class World {

++self.frameCount;
};

}

addObject(object) {
Expand All @@ -100,4 +103,8 @@ class World {
getObjectMesh(id) {
return this.scene.getObjectByName(id);
}
}
}




64 changes: 63 additions & 1 deletion src/main/resources/client/js/WorldObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class WorldObjectFactory extends ISocketUpdatableFactory {
case "robot": result = new Robot(this, json); break;
case "ambient_light": result = new AmbientLight(this, json); break;
case "floor": result = new Floor(this, json); break;
case "wall": result = new Wall(this, json); break;
case "shelf": result = new Shelf(this, json); break;
case "truck": result = new Truck(this, json); break;
default: result = new Unknown(this, json); break;
}

Expand Down Expand Up @@ -161,4 +164,63 @@ class Unknown extends IWorldObject {

return new THREE.Mesh(Unknown.Geometry, materials);
}
}

}

class Wall extends IWorldObject {
static Geometry = new THREE.BoxGeometry(1.0, 1.0, 1.0);
static Materials = [
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_wall.png" ), side: THREE.DoubleSide })
];

constructor(world, json) {
super(world, json);

this.texture = json.parameters.texture;
}

makeMesh() {
return new THREE.Mesh(Wall.Geometry, Wall.Materials);
}
}

class Shelf extends IWorldObject {
static Geometry = new THREE.BoxGeometry(1.0, 1.0, 1.0);
static Materials = [
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide }),
new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader(THREE.DefaultLoadingManager).load("textures/warehouse_shelf.png" ), side: THREE.DoubleSide })
];

constructor(world, json) {
super(world, json);

this.texture = json.parameters.texture;
}

makeMesh() {
return new THREE.Mesh(Shelf.Geometry, Shelf.Materials);
}
}

class Truck extends IWorldObject {

static Geometry = new THREE.BoxGeometry(1.8, 0.6, 1.8);
static loader = new THREE.ObjectLoader();
static truck = loader.load('models/delivery_truck.json');

makeMesh() {
return new THREE.Mesh(Truck.Geometry, Truck.truck);
}
}



Loading