-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Algorush/rotate-or-replace-tiles
Rotate or replace tiles
- Loading branch information
Showing
8 changed files
with
140 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* global AFRAME */ | ||
/** | ||
* change position of element by it's grid coordinates | ||
* | ||
*/ | ||
AFRAME.registerComponent('grid-coord', { | ||
schema: { | ||
gridCoord: {type: 'string', default: ''}, | ||
gridSize: {type: 'number', default: 5}, | ||
gridDivisions: {type: 'number', default: 20} | ||
}, | ||
init: function () { | ||
const data = this.data; | ||
const el = this.el; | ||
|
||
if (!data.gridCoord) { return; } | ||
|
||
[this.lon, this.lat] = data.gridCoord.split(','); | ||
|
||
const gridPos = this.stateToLocalGrid(data.gridSize, data.gridDivisions); | ||
|
||
el.setAttribute('position', gridPos); | ||
|
||
}, | ||
// Convert long / lat state grid coordinates to local grid position | ||
stateToLocalGrid: function (gridSize, gridDivisions) { | ||
// grid divisions (# of cells) ie 20 divisions | ||
// grid size (meter) ie 5 meters | ||
// cellsPerMeter: gridDivisions / gridSize = 4 cells per meter | ||
const cellsPerMeter = gridDivisions / gridSize; | ||
const snap = this.el.getAttribute('snap'); | ||
let snapOffset = (snap) ? snap['offset'] : 0.01; | ||
|
||
const [posLong, posLat] = | ||
[this.lon, this.lat].map((strVal) => { | ||
const numVal = Number(strVal); | ||
// add - or + snap offset is used to snap element to the desired grid cell | ||
return (numVal + (numVal >= 0 ? -snapOffset : snapOffset )) / cellsPerMeter; | ||
}); | ||
// console.log(`Lat Y: ${posLat}, Long X: ${posLong}`); | ||
|
||
const localPos = { | ||
x: posLong, | ||
z: posLat * -1 | ||
}; | ||
return localPos; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* global AFRAME */ | ||
/** | ||
* change gltf-model of element by model name | ||
* | ||
*/ | ||
AFRAME.registerComponent('grid-model', { | ||
schema: { | ||
model: {type: 'string', default: ''} | ||
}, | ||
addGltfModel: function (modelName) { | ||
const el = this.el; | ||
const sceneEl = el.sceneEl; | ||
|
||
if (sceneEl.catalogIsloaded) { | ||
el.setAttribute('gltf-model', './' + sceneEl.systems.state.state.model.list[modelName].dist); | ||
} else { | ||
sceneEl.addEventListener('catalogIsLoaded', () => { | ||
el.setAttribute('gltf-model', './' + sceneEl.systems.state.state.model.list[modelName].dist); | ||
}) | ||
} | ||
}, | ||
update: function(oldData) { | ||
this.addGltfModel(this.data.model); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* global AFRAME */ | ||
/** | ||
* change rotation of element by rotation value of y-axis | ||
* | ||
*/ | ||
AFRAME.registerComponent('grid-rotation', { | ||
schema: { | ||
rotation: {type: 'number', default: 0} | ||
}, | ||
update: function(oldData) { | ||
const data = this.data; | ||
const el = this.el; | ||
|
||
el.setAttribute('rotation', {x:0, y: data.rotation, z: 0}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters