mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 14:41:36 +02:00
Merge pull request #6367 from ericrius1/marketplace
Dynamic loading of models from specified directory
This commit is contained in:
commit
1819e20f74
4 changed files with 171 additions and 0 deletions
1
examples/marketplace/S3Server/Procfile
Normal file
1
examples/marketplace/S3Server/Procfile
Normal file
|
@ -0,0 +1 @@
|
|||
web: node index.js
|
57
examples/marketplace/S3Server/index.js
Normal file
57
examples/marketplace/S3Server/index.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// index.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 11/10/2015.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// This is a simple REST API that allows an interface client script to get a list of files paths from an S3 bucket.
|
||||
// To change your bucket, modify line 34 to your desired bucket.
|
||||
// Please refer to http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
|
||||
// for instructions on how to configure the SDK to work with your bucket.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
var AWS = require('aws-sdk');
|
||||
var url = require('url');
|
||||
var querystring = require('querystring');
|
||||
var _ = require('underscore');
|
||||
|
||||
AWS.config.update({
|
||||
region: "us-east-1"
|
||||
});
|
||||
|
||||
var s3 = new AWS.S3();
|
||||
|
||||
app.set('port', (process.env.PORT || 5000));
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
var urlParts = url.parse(req.url)
|
||||
var query = querystring.parse(urlParts.query);
|
||||
|
||||
var params = {
|
||||
Bucket: "hifi-public",
|
||||
Marker: query.assetDir,
|
||||
MaxKeys: 10
|
||||
};
|
||||
s3.listObjects(params, function(err, data) {
|
||||
if (err) {
|
||||
console.log(err, err.stack);
|
||||
res.send("ERROR")
|
||||
} else {
|
||||
var keys = _.pluck(data.Contents, 'Key')
|
||||
res.send({
|
||||
urls: keys
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.listen(app.get('port'), function() {
|
||||
console.log('Node app is running on port', app.get('port'));
|
||||
})
|
||||
|
18
examples/marketplace/S3Server/package.json
Normal file
18
examples/marketplace/S3Server/package.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "s3fileserver",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "eric",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.2.15",
|
||||
"express": "^4.13.3",
|
||||
"querystring": "^0.2.0",
|
||||
"underscore": "^1.8.3",
|
||||
"url": "^0.11.0"
|
||||
}
|
||||
}
|
95
examples/marketplace/dynamicLoader.js
Normal file
95
examples/marketplace/dynamicLoader.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// dynamicLoader.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 11/10/2015.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// This script is an example of a way to dynamically load and place models in a grid from a specified s3 directory on the hifi-public bucket.
|
||||
// The directory can be specified by changing the query string variable on line 19 to the desired relative path.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
|
||||
|
||||
var BASE_URL = "https://hifi-public.s3.amazonaws.com/";
|
||||
var models = [];
|
||||
var floorPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));;
|
||||
floorPosition.y = MyAvatar.position.y - 5;
|
||||
var floor = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: "https://hifi-public.s3.amazonaws.com/ozan/3d_marketplace/props/floor/3d_mp_floor.fbx",
|
||||
position: floorPosition,
|
||||
shapeType: 'box',
|
||||
dimensions: {
|
||||
x: 1000,
|
||||
y: 9,
|
||||
z: 1000
|
||||
}
|
||||
});
|
||||
|
||||
var urls = [];
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", "https://serene-headland-4300.herokuapp.com/?assetDir=ozan/3d_marketplace/sets", false);
|
||||
req.send();
|
||||
|
||||
var res = req.responseText;
|
||||
var urls = JSON.parse(res).urls;
|
||||
if (urls.length > 0) {
|
||||
// We've got an array of urls back from server- let's display them in grid
|
||||
createGrid();
|
||||
}
|
||||
|
||||
function createGrid() {
|
||||
var fbxUrls = urls.filter(function(url) {
|
||||
return url.indexOf('fbx') !== -1;
|
||||
});
|
||||
|
||||
var modelParams = {
|
||||
type: "Model",
|
||||
dimensions: {
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10
|
||||
},
|
||||
};
|
||||
|
||||
var modelPosition = {
|
||||
x: floorPosition.x + 10,
|
||||
y: floorPosition.y + 8.5,
|
||||
z: floorPosition.z
|
||||
};
|
||||
|
||||
for (var i = 0; i < fbxUrls.length; i++) {
|
||||
if(i % 2 === 0) {
|
||||
modelPosition.x = floorPosition.x - 40
|
||||
} else {
|
||||
modelPosition.x = floorPosition.x + 40
|
||||
}
|
||||
modelPosition.z -= 30;
|
||||
modelParams.position = modelPosition;
|
||||
modelParams.modelURL = BASE_URL + fbxUrls[i]
|
||||
var model = Entities.addEntity(modelParams);
|
||||
models.push(model);
|
||||
}
|
||||
|
||||
Script.setTimeout(function() {
|
||||
//Until we add callbacks on model loaded, we need to set a timeout and hope model is loaded by the time
|
||||
//we hit it in order to set model dimensions correctly
|
||||
for(var i = 0; i < models.length; i++){
|
||||
var modelDimensions = Entities.getEntityProperties(models[i], 'naturalDimensions').naturalDimensions;
|
||||
Entities.editEntity(models[i], {dimensions: modelDimensions});
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
Entities.deleteEntity(floor);
|
||||
models.forEach(function(model) {
|
||||
Entities.deleteEntity(model);
|
||||
});
|
||||
Entities.deleteEntity(model);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
Loading…
Reference in a new issue