UNPKG

meta-client

Version:
1 lines 3.56 kB
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _three=require('three');var THREE=_interopRequireWildcard(_three);require('./three/examples/js/loaders/GLTFLoader');var _Meta=require('../Meta');var _Meta2=_interopRequireDefault(_Meta);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var _DEFAULT={TYPE:'box'};var scope=void 0;var Graphics=function(){function Graphics(props){var _this=this;var stop=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;_classCallCheck(this,Graphics);scope=this;this.geometry=props!==undefined&&props.geometry!==undefined&&props.geometry!==true?props.geometry:new _three.CubeGeometry;this.material=props!==undefined&&props.material!==undefined&&props.material!==true?props.material:new _three.MeshPhongMaterial({color:Math.random()*16777215,side:_three.DoubleSide});this.type=props!==undefined&&props.type!==undefined&&props.type!==true?props.type:_DEFAULT.TYPE;this.mesh=props!==undefined&&props.mesh!==undefined&&props.mesh!==true?props.mesh:new _three.Mesh(this.geometry,this.material);this.model=props.model!==undefined?props.model:undefined;this.loader=undefined;if(this.model!==undefined){var _loadModel=function _loadModel(loader){loader.load(scope.model,function(gltf){scope.mesh.add(gltf.scene)})};this.model='models/'+this.model;this.mesh=new THREE.Object3D;var extentions=['gltf'];var loaders=['new THREE.GLTFLoader()'];if(this.model.includes('.')){var fileExtention=void 0;var pattern=/\.([0-9a-z]+)(?:[\?#]|$)/i;var result=this.model.match(pattern);fileExtention=result[1];scope.loader=eval(loaders[extentions.indexOf(fileExtention)]);_loadModel(scope.loader);return}extentions.forEach(function(extention){if(scope.loader!==undefined)return;fetch(_this.model+extention).then(function(response){if(response.status===200){scope.loader=eval(loaders[extentions.indexOf(extention)]);scope.model=scope.model+'.'+extention;_loadModel(scope.loader)}}).catch(function(error){return console.error(error)})})}this.physics=true;if(props.p!==undefined)this.physics=props.p;if(props.physics!==undefined)this.physics=props.physics;if(stop)return this;return new _Meta2.default({graphics:this,physics:this.physics})}_createClass(Graphics,[{key:'setPosition',value:function setPosition(position){this.mesh.position.copy(position);return this}},{key:'setRotation',value:function setRotation(rotation){this.mesh.rotation.x=rotation.x;this.mesh.rotation.y=rotation.y;this.mesh.rotation.z=rotation.z;return this}},{key:'color',value:function color(_color){return this}},{key:'add',value:function add(instance){this.geometry=instance}}]);return Graphics}();exports.default=Graphics;