mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 05:03:31 +02:00
Actual piece meshes
This commit is contained in:
parent
b4585163db
commit
d25af3b4c9
1 changed files with 147 additions and 36 deletions
|
@ -16,15 +16,57 @@ var ChessGame = ChessGame || {
|
|||
ROWS: ['1', '2', '3', '4', '5', '6', '7', '8'],
|
||||
COLUMNS: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
|
||||
|
||||
whitesTileColor: {red: 250, green: 195, blue: 135},
|
||||
blacksTileColor: {red: 190, green: 115, blue: 50},
|
||||
whiteKingURL: "http://public.highfidelity.io/models/attachments/King Piece.fst",
|
||||
whiteKingDimensions: { x: 0.46, y: 1.0, z: 0.46 },
|
||||
blackKingURL: "http://public.highfidelity.io/models/attachments/King Piece.fst",
|
||||
blackKingDimensions: { x: 0.46, y: 1.0, z: 0.46 },
|
||||
|
||||
whitesTileColor: { red: 250, green: 195, blue: 135 },
|
||||
blacksTileColor: { red: 190, green: 115, blue: 50 },
|
||||
|
||||
board: null,
|
||||
pieces: null
|
||||
pieces: {
|
||||
all: new Array(),
|
||||
king: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/King_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/King_Black.fbx",
|
||||
dimensions: { x: 110.496, y: 306.713, z: 110.496 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 90, 0)
|
||||
},
|
||||
queen: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Queen_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Queen_Black.fbx",
|
||||
dimensions: { x: 110.496, y: 257.459, z: 110.496 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
|
||||
},
|
||||
bishop: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Bishop_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Bishop_Black.fbx",
|
||||
dimensions: { x: 102.002, y: 213.941, z: 102.002 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
|
||||
white: [],
|
||||
black: []
|
||||
},
|
||||
knight: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Knight_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Knight_Black.fbx",
|
||||
dimensions: { x: 95.602, y: 186.939, z: 95.602 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 180, 0),
|
||||
white: [],
|
||||
black: []
|
||||
},
|
||||
rook: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Rook_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Rook_Black.fbx",
|
||||
dimensions: { x: 101.024, y: 167.523, z: 101.024 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
|
||||
white: [],
|
||||
black: []
|
||||
},
|
||||
pawn: {
|
||||
whiteURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Pawn_White.fbx",
|
||||
blackURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Pawn_Black.fbx",
|
||||
dimensions: { x: 93.317, y: 138.747, z: 93.317 },
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
|
||||
white: [],
|
||||
black: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -94,14 +136,16 @@ ChessGame.Board.prototype.cleanup = function() {
|
|||
}
|
||||
|
||||
// Piece class
|
||||
ChessGame.Piece = (function(position, size, url) {
|
||||
ChessGame.Piece = (function(position, size, url, rotation) {
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.entityProperties = {
|
||||
type: "Model",
|
||||
position: this.position,
|
||||
rotation: rotation,
|
||||
dimensions: this.size,
|
||||
modelURL: url,
|
||||
//script: "https://s3-us-west-1.amazonaws.com/highfidelity-dev/scripts/chessPiece.js"
|
||||
script: "file:/Users/clement/hifi/examples/entityScripts/chessPiece.js"
|
||||
}
|
||||
this.entity = null;
|
||||
|
@ -110,11 +154,30 @@ ChessGame.Piece = (function(position, size, url) {
|
|||
ChessGame.Piece.prototype.spawn = function() {
|
||||
this.entity = Entities.addEntity(this.entityProperties);
|
||||
}
|
||||
// Updates the metadata stored by the piece
|
||||
ChessGame.Piece.prototype.updateMetaData = function(metaDataString) {
|
||||
Entities.editEntity(this.entity, { animationURL: metaDataString });
|
||||
}
|
||||
// Cleans up the piece
|
||||
ChessGame.Piece.prototype.cleanup = function() {
|
||||
Entities.deleteEntity(this.entity);
|
||||
}
|
||||
|
||||
ChessGame.makePiece = function(properties, i, j, isWhite) {
|
||||
var url = (isWhite) ? properties.whiteURL : properties.blackURL;
|
||||
var size = Vec3.multiply(1.0 / ChessGame.pieces.king.dimensions.y,
|
||||
properties.dimensions);
|
||||
size = Vec3.multiply(1.5 * ChessGame.board.tileSize, size);
|
||||
var rotation = (isWhite) ? properties.rotation
|
||||
: Quat.multiply(Quat.fromPitchYawRollDegrees(0, 180, 0),
|
||||
properties.rotation);
|
||||
var position = Vec3.sum(ChessGame.board.tilePosition(i, j),
|
||||
{ x: 0, y: (size.y + ChessGame.board.height) / 2.0, z: 0});
|
||||
|
||||
var piece = new ChessGame.Piece(position, size, url, rotation);
|
||||
piece.spawn();
|
||||
ChessGame.pieces.all.push(piece);
|
||||
return piece;
|
||||
}
|
||||
|
||||
|
||||
// Player class
|
||||
|
@ -125,33 +188,81 @@ ChessGame.Player = (function() {
|
|||
ChessGame.update = function() {
|
||||
|
||||
}
|
||||
ChessGame.buildMetaDataString = function() {
|
||||
var metadataObject = {
|
||||
board: {
|
||||
position: ChessGame.board.position,
|
||||
size: ChessGame.board.size
|
||||
}
|
||||
};
|
||||
|
||||
return JSON.stringify(metadataObject);
|
||||
}
|
||||
|
||||
ChessGame.buildBoard = function() {
|
||||
// Setup board
|
||||
ChessGame.board = new ChessGame.Board({ x: 1, y: 1, z: 1 }, 1);
|
||||
ChessGame.board.spawn();
|
||||
|
||||
// Setup white pieces
|
||||
// King
|
||||
var piece = ChessGame.makePiece(ChessGame.pieces.king, 0, 3, true);
|
||||
ChessGame.pieces.king.white = piece;
|
||||
// Queen
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.queen, 0, 4, true);
|
||||
ChessGame.pieces.queen.white = piece;
|
||||
// Bishop
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.bishop, 0, 2, true);
|
||||
ChessGame.pieces.bishop.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.bishop, 0, 5, true);
|
||||
ChessGame.pieces.bishop.white.push(piece);
|
||||
// Knight
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.knight, 0, 1, true);
|
||||
ChessGame.pieces.knight.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.knight, 0, 6, true);
|
||||
ChessGame.pieces.knight.white.push(piece);
|
||||
// Rook
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.rook, 0, 0, true);
|
||||
ChessGame.pieces.rook.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.rook, 0, 7, true);
|
||||
ChessGame.pieces.rook.white.push(piece);
|
||||
for(var j = 0; j < ChessGame.BOARD_SIZE; j++) {
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.pawn, 1, j, true);
|
||||
ChessGame.pieces.pawn.white.push(piece);
|
||||
}
|
||||
|
||||
// Setup black pieces
|
||||
// King
|
||||
var piece = ChessGame.makePiece(ChessGame.pieces.king, 7, 3, false);
|
||||
ChessGame.pieces.king.white = piece;
|
||||
// Queen
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.queen, 7, 4, false);
|
||||
ChessGame.pieces.queen.white = piece;
|
||||
// Bishop
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.bishop, 7, 2, false);
|
||||
ChessGame.pieces.bishop.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.bishop, 7, 5, false);
|
||||
ChessGame.pieces.bishop.white.push(piece);
|
||||
// Knight
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.knight, 7, 1, false);
|
||||
ChessGame.pieces.knight.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.knight, 7, 6, false);
|
||||
ChessGame.pieces.knight.white.push(piece);
|
||||
// Rook
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.rook, 7, 0, false);
|
||||
ChessGame.pieces.rook.white.push(piece);
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.rook, 7, 7, false);
|
||||
ChessGame.pieces.rook.white.push(piece);
|
||||
for(var j = 0; j < ChessGame.BOARD_SIZE; j++) {
|
||||
piece = ChessGame.makePiece(ChessGame.pieces.pawn, 6, j, false);
|
||||
ChessGame.pieces.pawn.black.push(piece);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ChessGame.scriptStarting = function() {
|
||||
print("playChess.js started");
|
||||
ChessGame.board = new ChessGame.Board({ x: 1, y: 1, z: 1 }, 1);
|
||||
ChessGame.pieces = new Array();
|
||||
|
||||
var url = "http://public.highfidelity.io/models/attachments/King Piece.fst";
|
||||
var dimensions = { x: 0.46, y: 1.0, z: 0.46 };
|
||||
|
||||
var rowsIndex = [0, 1, 6, 7];
|
||||
for(var i in rowsIndex) {
|
||||
for(var j = 0; j < ChessGame.BOARD_SIZE; j++) {
|
||||
var size = Vec3.multiply(dimensions, ChessGame.board.tileSize);
|
||||
if (rowsIndex[i] == 1 || rowsIndex[i] == 6) {
|
||||
size = Vec3.multiply(size, 0.7);
|
||||
}
|
||||
var position = Vec3.sum(ChessGame.board.tilePosition(rowsIndex[i], j),
|
||||
{ x: 0, y: (size.y + ChessGame.board.height) / 2.0, z: 0});
|
||||
var color = (rowsIndex[i] < 4) ? ChessGame.whitesTileColor : ChessGame.blacksTileColor;
|
||||
|
||||
var piece = new ChessGame.Piece(position, size, url);
|
||||
piece.spawn();
|
||||
ChessGame.pieces.push(piece);
|
||||
}
|
||||
}
|
||||
|
||||
ChessGame.board.spawn();
|
||||
ChessGame.buildBoard();
|
||||
}
|
||||
|
||||
ChessGame.scriptEnding = function() {
|
||||
|
@ -160,8 +271,8 @@ ChessGame.scriptEnding = function() {
|
|||
delete ChessGame.board;
|
||||
|
||||
// Cleaning up pieces
|
||||
for(var i in ChessGame.pieces) {
|
||||
ChessGame.pieces[i].cleanup();
|
||||
for(var i in ChessGame.pieces.all) {
|
||||
ChessGame.pieces.all[i].cleanup();
|
||||
}
|
||||
delete ChessGame.pieces;
|
||||
|
||||
|
|
Loading…
Reference in a new issue