kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
205 lines (195 loc) • 9.62 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addShape = addShape;
exports.baseBox3FromObject = baseBox3FromObject;
exports.baseBoxHelper = baseBoxHelper;
exports.controlGeom = controlGeom;
exports.createRotShape = createRotShape;
exports.emptyBoxHolder = emptyBoxHolder;
exports.makeMBoxfromObject = makeMBoxfromObject;
exports.rotGeoms = rotGeoms;
exports.upwardsGeom = upwardsGeom;
var Three = _interopRequireWildcard(require("three"));
var _constants = require("../../constants");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function controlGeom() {
var vertices = new Float32Array([0, 0.02, 0.55, -0.08, 0, 0.5, -0.05, 0, 0.5, -0.05, 0, -0.5, -0.08, 0, -0.5, 0, 0.02, -0.55, 0.08, 0, -0.5, 0.05, 0, -0.5, 0.05, 0, 0.5, 0.08, 0, 0.5, 0, 0.02, 0.55, -0.08, 0.04, 0.5, -0.05, 0.04, 0.5, -0.05, 0.04, -0.5, -0.08, 0.04, -0.5, 0, 0.02, -0.55, 0.08, 0.04, -0.5, 0.05, 0.04, -0.5, 0.05, 0.04, 0.5, 0.08, 0.04, 0.5, 0, 0.02, 0.55]);
var indices = new Uint16Array([0, 1, 9, 4, 5, 6, 2, 3, 8, 3, 7, 8, 10, 11, 19, 14, 15, 16, 12, 13, 18, 13, 17, 18, 10, 1, 11, 10, 9, 19, 1, 2, 11, 2, 12, 11, 8, 9, 18, 9, 18, 19, 12, 2, 3, 12, 3, 13, 17, 7, 8, 17, 8, 18, 5, 4, 14, 15, 6, 16]);
var geometry = new Three.BufferGeometry();
geometry.setAttribute('position', new Three.BufferAttribute(vertices, 3));
geometry.setIndex(new Three.BufferAttribute(indices, 1));
return geometry;
}
function upwardsGeom() {
var vertices = new Float32Array([0.05, 0, 0.05, 0.05, 0.3, 0.05, 0.07, 0.3, 0.05, 0, 0.4, 0.05, -0.07, 0.3, 0.05, -0.05, 0.3, 0.05, -0.05, 0, 0.05, 0.05, 0, 0.05, 0.05, 0, -0.05, 0.05, 0.3, -0.05, 0.07, 0.3, -0.05, 0, 0.4, -0.05, -0.07, 0.3, -0.05, -0.05, 0.3, -0.05, -0.05, 0, -0.05, 0.05, 0, -0.05]);
var indices = new Uint16Array([0, 1, 5, 0, 5, 6, 2, 3, 4, 0, 1, 8, 1, 8, 9, 1, 2, 9, 2, 9, 10, 2, 3, 10, 3, 10, 11, 3, 4, 11, 4, 11, 12, 4, 5, 12, 4, 12, 13, 5, 6, 13, 6, 13, 14, 6, 7, 14, 7, 14, 15, 8, 9, 13, 8, 13, 14, 10, 11, 12]);
var geometry = new Three.BufferGeometry();
geometry.setAttribute('position', new Three.BufferAttribute(vertices, 3));
geometry.setIndex(new Three.BufferAttribute(indices, 1));
return geometry;
}
function createRotShape(radius) {
var rotShape = new Three.Shape();
rotShape.moveTo(Math.cos(-60 / 180 * Math.PI) * (radius - 0.05), Math.sin(-60 / 180 * Math.PI) * (radius - 0.05));
for (var i = -55; i <= 60; i += 5) {
rotShape.lineTo(Math.cos(i / 180 * Math.PI) * (radius - 0.05), Math.sin(i / 180 * Math.PI) * (radius - 0.05));
}
for (var _i = 60; _i >= -60; _i -= 5) {
if (_i === 5) {
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05), Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05) + 0.15, Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05) + 0.15, Math.sin(_i / 180 * Math.PI) * (radius + 0.05) + 0.1);
continue;
} else if (_i === 0) {
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05) + 0.25, Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
continue;
} else if (_i === -5) {
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05) + 0.15, Math.sin(_i / 180 * Math.PI) * (radius + 0.05) - 0.1);
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05) + 0.15, Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05), Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
continue;
}
rotShape.lineTo(Math.cos(_i / 180 * Math.PI) * (radius + 0.05), Math.sin(_i / 180 * Math.PI) * (radius + 0.05));
}
rotShape.lineTo(Math.cos(-60 / 180 * Math.PI) * (radius + 0.1), Math.sin(-60 / 180 * Math.PI) * (radius + 0.1));
rotShape.lineTo(Math.cos(-70 / 180 * Math.PI) * (radius + 0.0), Math.sin(-70 / 180 * Math.PI) * (radius + 0.0));
rotShape.lineTo(Math.cos(-60 / 180 * Math.PI) * (radius - 0.1), Math.sin(-60 / 180 * Math.PI) * (radius - 0.1));
rotShape.lineTo(Math.cos(-60 / 180 * Math.PI) * (radius - 0.05), Math.sin(-60 / 180 * Math.PI) * (radius - 0.05));
return rotShape;
}
function rotGeoms(radius) {
if (!Number.isFinite(radius)) radius = 1;
var rotShape = createRotShape(radius);
var rotFill = new Three.ShapeGeometry(rotShape);
var rotStroke = new Three.BufferGeometry().setFromPoints(rotShape.getPoints());
rotFill.rotateX(Math.PI / 2);
rotStroke.rotateX(Math.PI / 2);
return {
rotFill: rotFill,
rotStroke: rotStroke
};
}
function addShape(shape, extrudeSettings, color, x, y, z, rx, ry, rz, s) {
// flat shape
var geometry = geometry = new Three.ExtrudeGeometry(shape, extrudeSettings);
var mesh = new Three.Mesh(geometry, new Three.MeshPhongMaterial({
color: color,
side: Three.DoubleSide
}));
mesh.position.set(x, y, z);
mesh.rotation.set(rx, ry, rz);
mesh.scale.set(s, s, s);
return mesh;
}
function makeMBoxfromObject(props_Object) {
var _props_Object$childre;
var mBoxColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0x99c3fb;
if (!props_Object) {
console.warn('makeMBoxfromObject: props_Object is null or undefined');
return null;
}
// safe resolve of object (skip wrapper Group)
var object = props_Object;
if (props_Object.children && ((_props_Object$childre = props_Object.children[0]) === null || _props_Object$childre === void 0 ? void 0 : _props_Object$childre.type) === 'Group') {
object = props_Object.children[0];
}
if (!object) {
console.warn('makeMBoxfromObject: object is null after resolving children');
return null;
}
var _object = object,
scale = _object.scale,
position = _object.position,
userData = _object.userData;
if (!scale) {
console.warn('makeMBoxfromObject: object.scale is missing');
return null;
}
if (!position) {
console.warn('makeMBoxfromObject: object.position is missing');
return null;
}
if (!userData) {
console.warn('makeMBoxfromObject: object.userData is missing');
return null;
}
if (!userData.max || !userData.min) {
console.warn('makeMBoxfromObject: userData.max or userData.min is missing');
return null;
}
var scaleVec = new Three.Vector3(scale.x, scale.y, scale.z);
var posVec = new Three.Vector3(position.x, position.y, position.z);
var uVec = new Three.Vector3(-posVec.x / scaleVec.x, -posVec.y / scaleVec.y, -posVec.z / scaleVec.z);
var max = userData.max,
min = userData.min;
var moveBox = new Three.BoxGeometry(max.x - min.x, max.y - min.y, max.z - min.z);
var mBox = new Three.Mesh(moveBox, new Three.MeshBasicMaterial({
color: mBoxColor,
side: Three.DoubleSide,
transparent: true,
opacity: 0.4
}));
mBox.name = 'TransformBox';
mBox.translateOnAxis(new Three.Vector3(uVec.x, uVec.y + (max.y - min.y) / 2, uVec.z), 1);
mBox.scale.set(1.1, 1.1, 1.1);
mBox.translateY(posVec.y);
mBox.renderOrder = 1;
mBox.visible = mBoxColor !== 0x99c3fb;
return mBox;
}
// export function rotMesh(radius) {
// let rotShape = rotShape(radius);
// let rotGeom = new Three.ShapeBufferGeometry(rotShape);
// const points = rotShape.getPoints();
// const spacedPoints = shape.getSpacedPoints( 50 );
// const geometryPoints = new THREE.BufferGeometry().setFromPoints( points );
// const geometrySpacedPoints = new THREE.BufferGeometry().setFromPoints( spacedPoints );
// // solid line
// let line = new THREE.Line( geometryPoints, new THREE.LineBasicMaterial( { color: color } ) );
// line.position.set( x, y, z - 25 );
// line.rotation.set( rx, ry, rz );
// line.scale.set( s, s, s );
// group.add( line );
// }
function baseBoxHelper(object, color) {
var tempobj = [];
for (var j = object.children.length - 1; j >= 0; j--) {
if (object.children[j].type !== _constants.OBJTYPE_MESH) {
tempobj.push(object.children[j]);
object.remove(object.children[j]);
}
}
var boxHelper = new Three.BoxHelper(object, color);
tempobj.forEach(function (v) {
object.add(v);
});
return boxHelper;
}
function baseBox3FromObject(object) {
var tempobj = [];
for (var j = object.children.length - 1; j >= 0; j--) {
if (object.children[j].type !== _constants.OBJTYPE_MESH || object.children[j].name.includes('_countertop')) {
tempobj.push(object.children[j]);
object.remove(object.children[j]);
}
}
var box3 = new Three.Box3().setFromObject(object);
tempobj.forEach(function (v) {
object.add(v);
});
return box3;
}
function emptyBoxHolder(newWidth, newHeight, newDepth) {
var scale = 2.54 / 100;
var geometry = new Three.BoxGeometry(newWidth * scale, newHeight * scale, newDepth * scale);
var material = new Three.MeshBasicMaterial({
color: 0x00ff00,
opacity: 0.2,
transparent: true
});
var cube = new Three.Mesh(geometry, material);
return cube;
}