awv3
Version:
⚡ AWV3 embedded CAD
132 lines (113 loc) • 3.9 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _extends from "@babel/runtime/helpers/extends";
import * as THREE from 'three';
import { actions as connectionActions } from '../../session/store/connections';
import { actions as globalActions } from '../../session/store/globals';
import Plugin from '../../session/plugin';
import { Slider, Spacer, Group, Button, Input, Label, Selection, Checkbox, Dropdown, Console } from '../../session/elements';
var resources = ['isometric'].reduce(function (prev, item) {
var _extends2;
return _extends({}, prev, (_extends2 = {}, _extends2[item] = require('!!url-loader!awv3-icons/32x32/' + item + '.png'), _extends2));
}, {});
var Color =
/*#__PURE__*/
function (_Plugin) {
_inheritsLoose(Color, _Plugin);
function Color(session, args) {
var _this;
_this = _Plugin.call(this, session, _extends({
type: 'Color',
icon: 'isometric',
resources: resources
}, args)) || this;
_this.solid = new Selection(_assertThisInitialized(_this), {
name: 'Solid',
types: ['Part', 'Mesh']
});
_this.refsGroup = new Group(_assertThisInitialized(_this), {
format: Group.Format.Table,
children: [_this.solid]
});
_this.addElement(_this.refsGroup);
_this.addElement(new Spacer(_assertThisInitialized(_this)));
_this.noCut = new Button(_assertThisInitialized(_this), {
name: 'ISO NoCut',
color: 'rgb(160,160,160)'
});
_this.cut = new Button(_assertThisInitialized(_this), {
name: 'ISO Cut',
color: 'rgb(204,204,204)'
});
var buttonGroup = new Group(_assertThisInitialized(_this), {
format: Group.Format.Buttons,
children: [_this.noCut, _this.cut],
flex: 3
});
_this.color = new Button(_assertThisInitialized(_this), {
name: 'Any Color',
format: Button.Format.Color,
color: '#28d79f',
flex: 1
});
var spacer = new Spacer(_assertThisInitialized(_this));
var group = new Group(_assertThisInitialized(_this), {
format: Group.Format.Rows,
children: [buttonGroup, spacer, _this.color]
});
_this.addElement(group);
return _this;
}
var _proto = Color.prototype;
_proto.setColor = function setColor() {
var connection = this.session.globals.activeConnection;
var selected = this.session.selector.selectedObjects;
console.log(selected);
if (selected.length) {
selected = selected[0];
for (var _len = arguments.length, rgb = new Array(_len), _key = 0; _key < _len; _key++) {
rgb[_key] = arguments[_key];
}
this.store.dispatch(connectionActions.setColor(connection, selected.userData.parentId, rgb));
var color = new THREE.Color("rgb(" + rgb.join(',') + ")");
selected.animate({
materials: {
meshes: [{
color: color,
opacity: 1
}]
}
}).start(0);
selected.__origProps = selected.animate({
materials: {
meshes: [{
color: color,
opacity: 1
}]
}
}).getProperties();
}
};
_proto.onEnabled = function onEnabled() {
var _this2 = this;
this.resetElements();
this.noCut.observe(function (state) {
return state.lastEvent;
}, function (event) {
return _this2.setColor(128, 128, 128);
});
this.cut.observe(function (state) {
return state.lastEvent;
}, function (event) {
return _this2.setColor(204, 204, 204);
});
this.color.observe(function (state) {
return state.lastEvent;
}, function (event) {
var color = new THREE.Color(event.color);
_this2.setColor(color.r * 255, color.g * 255, color.b * 255);
});
};
return Color;
}(Plugin);
export { Color as default };