chore: build omi-three
This commit is contained in:
parent
8831af8100
commit
88de93d12b
|
@ -1,193 +0,0 @@
|
|||
/*!
|
||||
* omi-canvas v0.0.0 By dntzhang
|
||||
* Github: https://github.com/AlloyTeam/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory(require("omi"), require("cax"));
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define(["omi", "cax"], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["OmiCanvas"] = factory(require("omi"), require("cax"));
|
||||
else
|
||||
root["OmiCanvas"] = factory(root["omi"], root["cax"]);
|
||||
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
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 _omi = __webpack_require__(1);
|
||||
|
||||
var _cax = __webpack_require__(2);
|
||||
|
||||
var _cax2 = _interopRequireDefault(_cax);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var caxProps = ['x', 'y', 'scaleX', 'scaleY', 'scale', 'rotation', 'skewX', 'skewY', 'originX', 'originY', 'alpha', 'compositeOperation', 'cursor', 'fixed', 'shadow'];
|
||||
|
||||
(0, _omi.define)('omi-canvas', function (_WeElement) {
|
||||
_inherits(_class, _WeElement);
|
||||
|
||||
function _class() {
|
||||
_classCallCheck(this, _class);
|
||||
|
||||
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(_class, [{
|
||||
key: 'install',
|
||||
|
||||
//static noSlot = true
|
||||
|
||||
value: function install() {}
|
||||
}, {
|
||||
key: 'installed',
|
||||
value: function installed() {
|
||||
this.stage = new _cax2['default'].Stage(this.canvas);
|
||||
render(this.props.children, this.stage);
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
value: function render(props) {
|
||||
var _this2 = this;
|
||||
|
||||
return Omi.h('canvas', {
|
||||
style: props.css,
|
||||
ref: function ref(e) {
|
||||
_this2.canvas = e;
|
||||
},
|
||||
width: props.width,
|
||||
height: props.height });
|
||||
}
|
||||
}]);
|
||||
|
||||
return _class;
|
||||
}(_omi.WeElement));
|
||||
|
||||
function render(children, stage) {
|
||||
children.forEach(function (child) {
|
||||
var attr = child.attributes;
|
||||
switch (child.nodeName) {
|
||||
case 'text':
|
||||
var text = new _cax2['default'].Text(attr.text, {
|
||||
font: attr.font,
|
||||
color: attr.color,
|
||||
baseline: attr.baseline
|
||||
});
|
||||
mix(attr, text);
|
||||
console.log(text.x);
|
||||
stage.add(text);
|
||||
break;
|
||||
case 'bitmap':
|
||||
var bitmap = new _cax2['default'].Bitmap(attr.src, function () {
|
||||
stage.update();
|
||||
});
|
||||
stage.add(bitmap);
|
||||
mix(attr, bitmap);
|
||||
}
|
||||
});
|
||||
|
||||
stage.update();
|
||||
}
|
||||
|
||||
function mix(attr, obj) {
|
||||
caxProps.forEach(function (prop) {
|
||||
if (attr.hasOwnProperty(prop)) {
|
||||
obj[prop] = attr[prop];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
});
|
|
@ -1,6 +0,0 @@
|
|||
/*!
|
||||
* omi-canvas v0.0.0 By dntzhang
|
||||
* Github: https://github.com/AlloyTeam/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("omi"),require("cax")):"function"==typeof define&&define.amd?define(["omi","cax"],t):"object"==typeof exports?exports.OmiCanvas=t(require("omi"),require("cax")):e.OmiCanvas=t(e.omi,e.cax)}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){e.forEach(function(e){var n=e.attributes;switch(e.nodeName){case"text":var o=new l.default.Text(n.text,{font:n.font,color:n.color,baseline:n.baseline});u(n,o),console.log(o.x),t.add(o);break;case"bitmap":var r=new l.default.Bitmap(n.src,function(){t.update()});t.add(r),u(n,r)}}),t.update()}function u(e,t){p.forEach(function(n){e.hasOwnProperty(n)&&(t[n]=e[n])})}var c=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),f=n(1),s=n(2),l=function(e){return e&&e.__esModule?e:{default:e}}(s),p=["x","y","scaleX","scaleY","scale","rotation","skewX","skewY","originX","originY","alpha","compositeOperation","cursor","fixed","shadow"];(0,f.define)("omi-canvas",function(e){function t(){return o(this,t),r(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return i(t,e),c(t,[{key:"install",value:function(){}},{key:"installed",value:function(){this.stage=new l.default.Stage(this.canvas),a(this.props.children,this.stage)}},{key:"render",value:function(e){var t=this;return Omi.h("canvas",{style:e.css,ref:function(e){t.canvas=e},width:e.width,height:e.height})}}]),t}(f.WeElement))},function(t,n){t.exports=e},function(e,n){e.exports=t}])});
|
|
@ -0,0 +1,370 @@
|
|||
/*!
|
||||
* omi-three v0.0.0 By dntzhang
|
||||
* Github: https://github.com/AlloyTeam/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory(require("three"), require("omi"));
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define(["three", "omi"], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["OmiThree"] = factory(require("three"), require("omi"));
|
||||
else
|
||||
root["OmiThree"] = factory(root["three"], root["omi"]);
|
||||
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_2__) {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 1);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
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 _omi = __webpack_require__(2);
|
||||
|
||||
var _three = __webpack_require__(0);
|
||||
|
||||
var THREE = _interopRequireWildcard(_three);
|
||||
|
||||
var _objectPool = __webpack_require__(3);
|
||||
|
||||
var _objectPool2 = _interopRequireDefault(_objectPool);
|
||||
|
||||
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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
(0, _omi.define)('omi-three', function (_WeElement) {
|
||||
_inherits(_class, _WeElement);
|
||||
|
||||
function _class() {
|
||||
_classCallCheck(this, _class);
|
||||
|
||||
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(_class, [{
|
||||
key: 'installed',
|
||||
value: function installed() {
|
||||
|
||||
this.scene = new THREE.Scene();
|
||||
this.renderer = new THREE.WebGLRenderer({
|
||||
canvas: this.canvas
|
||||
});
|
||||
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
this.pool = new _objectPool2['default']();
|
||||
this.threeRender();
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
value: function render(props) {
|
||||
var _this2 = this;
|
||||
|
||||
return Omi.h('canvas', {
|
||||
style: props.css,
|
||||
ref: function ref(e) {
|
||||
_this2.canvas = e;
|
||||
},
|
||||
width: props.width,
|
||||
height: props.height });
|
||||
}
|
||||
}, {
|
||||
key: 'threeRender',
|
||||
value: function threeRender() {
|
||||
var _this3 = this;
|
||||
|
||||
this.props.children.forEach(function (child) {
|
||||
var obj = _this3.pool.getObj(child.nodeName, child, _this3.scene);
|
||||
obj && _this3.scene.add(obj);
|
||||
});
|
||||
|
||||
this.renderer.render(this.scene, this.scene.camera);
|
||||
}
|
||||
}, {
|
||||
key: 'update',
|
||||
value: function update() {
|
||||
//this.scene.empty()
|
||||
this.pool.reset();
|
||||
this.threeRender(this.props.children, this.scene, this.pool);
|
||||
}
|
||||
}]);
|
||||
|
||||
return _class;
|
||||
}(_omi.WeElement));
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"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 = __webpack_require__(0);
|
||||
|
||||
var THREE = _interopRequireWildcard(_three);
|
||||
|
||||
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 caxProps = ['rotation'];
|
||||
|
||||
var ObjectPool = function () {
|
||||
function ObjectPool() {
|
||||
_classCallCheck(this, ObjectPool);
|
||||
|
||||
this.textList = [];
|
||||
this.usingMesh = [];
|
||||
this.testListUsing = [];
|
||||
this.bitmapListUsing = [];
|
||||
|
||||
this.groupList = [];
|
||||
this.groupListUsing = [];
|
||||
}
|
||||
|
||||
_createClass(ObjectPool, [{
|
||||
key: 'reset',
|
||||
value: function reset() {
|
||||
var _this = this;
|
||||
|
||||
this.testListUsing.forEach(function (item) {
|
||||
_this.textList.push(item);
|
||||
});
|
||||
this.bitmapListUsing.forEach(function (item) {
|
||||
_this.bitmapList.push(item);
|
||||
});
|
||||
this.groupListUsing.forEach(function (item) {
|
||||
_this.groupList.push(item);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getObj',
|
||||
value: function getObj(type, vnode, scene) {
|
||||
var _this2 = this;
|
||||
|
||||
var attr = vnode.attributes;
|
||||
switch (type) {
|
||||
case 'text':
|
||||
if (this.textList.length > 0) {
|
||||
var obj = this.textList[0];
|
||||
reset(obj);
|
||||
mix(attr, obj);
|
||||
return obj;
|
||||
} else {
|
||||
//https://github.com/dntzhang/cax/blob/master/packages/cax/src/render/display/text.js
|
||||
var text = new cax.Text(attr.text, {
|
||||
font: attr.font,
|
||||
color: attr.color,
|
||||
baseline: attr.baseline
|
||||
});
|
||||
mix(attr, text);
|
||||
this.testListUsing.push(text);
|
||||
return text;
|
||||
}
|
||||
case 'group':
|
||||
if (this.groupList.length > 0) {
|
||||
var _obj = this.groupList[0];
|
||||
reset(_obj);
|
||||
mix(attr, _obj);
|
||||
|
||||
_obj.children.forEach(function (child) {
|
||||
_obj.remove(child);
|
||||
});
|
||||
|
||||
vnode.children.forEach(function (child) {
|
||||
_obj.add(_this2.getObj(child.nodeName, child, scene));
|
||||
});
|
||||
|
||||
return _obj;
|
||||
} else {
|
||||
var group = new THREE.Group();
|
||||
mix(attr, group);
|
||||
this.groupListUsing.push(group);
|
||||
vnode.children.forEach(function (child) {
|
||||
group.add(_this2.getObj(child.nodeName, child, scene));
|
||||
});
|
||||
return group;
|
||||
}
|
||||
|
||||
case 'mesh':
|
||||
|
||||
var geometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
Object.assign(mesh.rotation, attr.rotation);
|
||||
this.usingMesh.push(mesh);
|
||||
|
||||
return mesh;
|
||||
case 'perspective-camera':
|
||||
scene.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
scene.camera.position.z = 5;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'add',
|
||||
value: function add(type) {
|
||||
switch (type) {
|
||||
case 'text':
|
||||
break;
|
||||
case 'bitmap':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
return ObjectPool;
|
||||
}();
|
||||
|
||||
exports['default'] = ObjectPool;
|
||||
|
||||
|
||||
function reset(obj) {
|
||||
// obj.x = 0
|
||||
// obj.y = 0
|
||||
// obj.scale = 1
|
||||
obj.rotation.x = 0;
|
||||
obj.rotation.y = 0;
|
||||
obj.rotation.z = 0;
|
||||
// obj.skewX = 0
|
||||
// obj.skewY = 0
|
||||
// obj.originX = 0
|
||||
// obj.originY = 0
|
||||
// obj.alpha = 1
|
||||
// obj.compositeOperation = null
|
||||
// obj.cursor = 'default'
|
||||
// obj.fixed = false
|
||||
// obj.shadow = null
|
||||
}
|
||||
|
||||
function mix(attr, obj) {
|
||||
if (!attr) return;
|
||||
caxProps.forEach(function (prop) {
|
||||
if (attr.hasOwnProperty(prop)) {
|
||||
obj[prop] = attr[prop];
|
||||
}
|
||||
});
|
||||
|
||||
//bindEvent
|
||||
// Object.keys(attr).forEach(key => {
|
||||
// if (key[0] == 'o' && key[1] == 'n') {
|
||||
// const type = key.toLowerCase().substring(2)
|
||||
// obj.on(type, attr[key])
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
// getImageInfo(attr.src, (w, h, img) => {
|
||||
// obj.rect[0] = 0
|
||||
// obj.rect[1] = 0
|
||||
// obj.rect[2] = w
|
||||
// obj.rect[3] = h
|
||||
// obj.width = w
|
||||
// obj.height = h
|
||||
// obj.img = img
|
||||
|
||||
|
||||
// })
|
||||
// const img = new Image()
|
||||
// function getImageInfo(src, callback) {
|
||||
|
||||
// img.onload = () => {
|
||||
// callback(img.width, img.height, img)
|
||||
// }
|
||||
// img.src = src
|
||||
// }
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
/*!
|
||||
* omi-three v0.0.0 By dntzhang
|
||||
* Github: https://github.com/AlloyTeam/omi
|
||||
* MIT Licensed.
|
||||
*/
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("three"),require("omi")):"function"==typeof define&&define.amd?define(["three","omi"],t):"object"==typeof exports?exports.OmiThree=t(require("three"),require("omi")):e.OmiThree=t(e.three,e.omi)}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(2),a=n(0),c=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(a),f=n(3),h=function(e){return e&&e.__esModule?e:{default:e}}(f);(0,u.define)("omi-three",function(e){function t(){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return o(t,e),s(t,[{key:"installed",value:function(){this.scene=new c.Scene,this.renderer=new c.WebGLRenderer({canvas:this.canvas}),this.renderer.setSize(window.innerWidth,window.innerHeight),this.pool=new h.default,this.threeRender()}},{key:"render",value:function(e){var t=this;return Omi.h("canvas",{style:e.css,ref:function(e){t.canvas=e},width:e.width,height:e.height})}},{key:"threeRender",value:function(){var e=this;this.props.children.forEach(function(t){var n=e.pool.getObj(t.nodeName,t,e.scene);n&&e.scene.add(n)}),this.renderer.render(this.scene,this.scene.camera)}},{key:"update",value:function(){this.pool.reset(),this.threeRender(this.props.children,this.scene,this.pool)}}]),t}(u.WeElement))},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){e.rotation.x=0,e.rotation.y=0,e.rotation.z=0}function o(e,t){e&&c.forEach(function(n){e.hasOwnProperty(n)&&(t[n]=e[n])})}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(u),c=["rotation"],f=function(){function e(){r(this,e),this.textList=[],this.usingMesh=[],this.testListUsing=[],this.bitmapListUsing=[],this.groupList=[],this.groupListUsing=[]}return s(e,[{key:"reset",value:function(){var e=this;this.testListUsing.forEach(function(t){e.textList.push(t)}),this.bitmapListUsing.forEach(function(t){e.bitmapList.push(t)}),this.groupListUsing.forEach(function(t){e.groupList.push(t)})}},{key:"getObj",value:function(e,t,n){var r=this,s=t.attributes;switch(e){case"text":if(this.textList.length>0){var u=this.textList[0];return i(u),o(s,u),u}var c=new cax.Text(s.text,{font:s.font,color:s.color,baseline:s.baseline});return o(s,c),this.testListUsing.push(c),c;case"group":if(this.groupList.length>0){var f=this.groupList[0];return i(f),o(s,f),f.children.forEach(function(e){f.remove(e)}),t.children.forEach(function(e){f.add(r.getObj(e.nodeName,e,n))}),f}var h=new a.Group;return o(s,h),this.groupListUsing.push(h),t.children.forEach(function(e){h.add(r.getObj(e.nodeName,e,n))}),h;case"mesh":var l=new a.BoxGeometry(1,1,1),p=new a.MeshBasicMaterial({color:65280}),d=new a.Mesh(l,p);return Object.assign(d.rotation,s.rotation),this.usingMesh.push(d),d;case"perspective-camera":return n.camera=new a.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,1e3),n.camera.position.z=5,null}}},{key:"add",value:function(e){e}}]),e}();t.default=f}])});
|
|
@ -57,19 +57,19 @@ var config = {
|
|||
if(ENV === 'build'||ENV === 'build-min'){
|
||||
config = {
|
||||
entry: {
|
||||
'omi-canvas': './src/index.js'
|
||||
'omi-three': './src/index.js'
|
||||
},
|
||||
output: {
|
||||
// path: __dirname,
|
||||
path: path.join(__dirname, 'dist/'),
|
||||
library:'OmiCanvas',
|
||||
library:'OmiThree',
|
||||
libraryTarget: 'umd',
|
||||
filename: '[name].js'
|
||||
//umdNamedDefine: true
|
||||
},
|
||||
externals: {
|
||||
"omi": 'omi',
|
||||
"cax": 'cax'
|
||||
"three": 'three'
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
|
@ -90,7 +90,7 @@ if(ENV === 'build'||ENV === 'build-min'){
|
|||
},
|
||||
plugins: [
|
||||
// Avoid publishing files when compilation fails
|
||||
new webpack.BannerPlugin(" omi-canvas v"+packageJSON.version+" By dntzhang \r\n Github: https://github.com/AlloyTeam/omi\r\n MIT Licensed."),
|
||||
new webpack.BannerPlugin(" omi-three v"+packageJSON.version+" By dntzhang \r\n Github: https://github.com/AlloyTeam/omi\r\n MIT Licensed."),
|
||||
new webpack.NoEmitOnErrorsPlugin()
|
||||
],
|
||||
stats: {
|
||||
|
@ -104,7 +104,7 @@ if(ENV === 'build'||ENV === 'build-min'){
|
|||
if(ENV === 'build-min'){
|
||||
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
|
||||
config.entry = {
|
||||
'omi-canvas.min': './src/index.js'
|
||||
'omi-three.min': './src/index.js'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue