Skip to content

Commit

Permalink
- refactor: moved some constant definitions
Browse files Browse the repository at this point in the history
- feat: implemented location-based package (only 1 location)
  • Loading branch information
le0m committed Jun 1, 2020
1 parent 414710e commit e68db97
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 36 deletions.
14 changes: 6 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import 'regenerator-runtime/runtime';
import { LocationModule } from './modules/location';
import { MarkerModule } from './modules/marker';
import { NFTModule } from './modules/nft';
import {
Package,
ASSET_3D,
ASSET_IMAGE,
ASSET_AUDIO,
ASSET_VIDEO,
AR_BARCODE,
AR_PATTERN,
AR_LOCATION,
AR_NTF,
} from './modules/package/Package';
import {
MarkerModule,
ASSET_3D,
ASSET_IMAGE,
ASSET_AUDIO,
ASSET_VIDEO,
} from './modules/marker';
import { NFTModule } from './modules/nft';
import {
MATRIX_3X3_HAMMING_63,
MATRIX_3X3_PARITY_65,
Expand Down
26 changes: 21 additions & 5 deletions src/modules/location/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import {
ASSET_3D,
ASSET_IMAGE,
ASSET_AUDIO,
ASSET_VIDEO,
} from '../../index';

import location3dTemplate from './templates/location.3d.handlebars';
import locationImageTemplate from './templates/location.image.handlebars';
import locationAudioTemplate from './templates/location.audio.handlebars';
import locationVideoTemplate from './templates/location.video.handlebars';

const TEMPLATES = {
[ASSET_3D]: location3dTemplate,
[ASSET_IMAGE]: locationImageTemplate,
[ASSET_AUDIO]: locationAudioTemplate,
[ASSET_VIDEO]: locationVideoTemplate,
};

export class LocationModule {
static generateLocation3dHtml(longitude, latitude, assetSrc) {
return location3dTemplate({
longitude,
latitude,
assetSrc,
static generateHtml(assetType, assetParam, assetPath) {
return TEMPLATES[assetType]({
assetParam,
assetPath,
});
}
}
2 changes: 1 addition & 1 deletion src/modules/location/templates/location.3d.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
animation-mixer="loop: repeat"
gltf-model="#animated-asset"
scale="{{assetParam.scale}} {{assetParam.scale}} {{assetParam.scale}}"
gps-entity-place="latitude: {{latitude}}; longitude: {{longitude}};"
gps-entity-place="latitude: {{assetParam.latitude}}; longitude: {{assetParam.longitude}};"
></a-entity>

<a-camera gps-camera rotation-reader></a-camera>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/location/templates/location.audio.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
sound="src: #sound"
emitsevent
autoplay="false"
gps-entity-place="latitude: {{latitude}}; longitude: {{longitude}};"
gps-entity-place="latitude: {{assetParam.latitude}}; longitude: {{assetParam.longitude}};"
></a-entity>

<a-camera gps-camera rotation-reader></a-camera>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/location/templates/location.image.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
src="{{assetPath}}"
look-at="[gps-camera]"
scale="{{assetParam.scale}} {{assetParam.scale}} {{assetParam.scale}}"
gps-entity-place="latitude: {{latitude}}; longitude: {{longitude}};"
gps-entity-place="latitude: {{assetParam.latitude}}; longitude: {{assetParam.longitude}};"
></a-image>

<a-camera gps-camera rotation-reader></a-camera>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/location/templates/location.video.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
smoothThreshold="5"
autoplay="false"
scale="{{assetParam.scale}} {{assetParam.scale}} {{assetParam.scale}}"
gps-entity-place="latitude: {{latitude}}; longitude: {{longitude}};"
gps-entity-place="latitude: {{assetParam.latitude}}; longitude: {{assetParam.longitude}};"
></a-video>

<a-camera gps-camera rotation-reader></a-camera>
Expand Down
12 changes: 7 additions & 5 deletions src/modules/marker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
ASSET_3D,
ASSET_IMAGE,
ASSET_AUDIO,
ASSET_VIDEO,
} from '../../index';

import { BarcodeMarkerGenerator } from './tools/barcode-marker-generator';
import { PatternMarkerGenerator } from './tools/pattern-marker-generator';
import barcodeTemplate from './templates/barcode.handlebars';
Expand All @@ -6,11 +13,6 @@ import patternImageTemplate from './templates/pattern.image.handlebars';
import patternAudioTemplate from './templates/pattern.audio.handlebars';
import patternVideoTemplate from './templates/pattern.video.handlebars';

export const ASSET_3D = '3d';
export const ASSET_IMAGE = 'image';
export const ASSET_AUDIO = 'audio';
export const ASSET_VIDEO = 'video';

const TEMPLATES = {
[ASSET_3D]: pattern3dTemplate,
[ASSET_IMAGE]: patternImageTemplate,
Expand Down
35 changes: 21 additions & 14 deletions src/modules/package/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
ENC_BINARY,
ZipProvider,
GithubProvider,
} from '../../providers';
import {
ASSET_3D,
ASSET_IMAGE,
ASSET_AUDIO,
ASSET_VIDEO,
MarkerModule,
} from '../marker';
LocationModule,
} from '../../index';

export const ASSET_3D = '3d';
export const ASSET_IMAGE = 'image';
export const ASSET_AUDIO = 'audio';
export const ASSET_VIDEO = 'video';

export const AR_BARCODE = 'barcode';
export const AR_PATTERN = 'pattern';
Expand All @@ -23,6 +23,8 @@ export const AR_NTF = 'ntf';
* @property {boolean} isValid
* @property {Number} scale
* @property {{width: Number, height: Number, depth: Number}} size
* @property {Number} [latitude] - only for location-based
* @property {Number} [longitude] - only for location-based
*/
const defaultAssetParam = {
isValid: true,
Expand Down Expand Up @@ -85,16 +87,13 @@ export class Package {

case AR_PATTERN:
generatedHtml = MarkerModule.generatePatternHtml(this.assetType, this.assetParam, `assets/${this.assetName}`);

if (!this.config.markerPatt) {
throw new Error('Pattern-based AR needs a marker.patt file');
}

provider.addFile('assets/marker.patt', this.config.markerPatt);
this.addMarkerToProvider(provider, this.config.markerPatt);
break;

case AR_LOCATION:
throw new Error('Location template is not implemented');
generatedHtml = LocationModule.generateHtml(this.assetType, this.assetParam, `assets/${this.assetName}`);
this.addMarkerToProvider(provider, this.config.markerPatt);
break;

case AR_NTF:
throw new Error('NTF template is not implemented');
Expand Down Expand Up @@ -158,4 +157,12 @@ export class Package {
throw new Error(`Unknown asset type: ${this.assetType}`);
}
}

addMarkerToProvider(provider, markerPatt) {
if (!markerPatt) {
throw new Error('Missing marker.patt file');
}

provider.addFile('assets/marker.patt', markerPatt);
}
}

0 comments on commit e68db97

Please sign in to comment.