This commit is contained in:
casperlamboo 2017-12-14 11:16:27 +01:00
parent 15f2237d27
commit ec72a0097d
13 changed files with 45 additions and 40 deletions

View File

@ -62,7 +62,7 @@ class D3Panel extends React.Component {
componentWillMount() { componentWillMount() {
this.createScene(); this.createScene();
const toonShader = hasExtensionsFor.toonShaderPreview const toonShader = hasExtensionsFor.toonShaderPreview;
this.renderChain = new RenderChain(this.renderer, this.scene, this.camera, toonShader, { this.renderChain = new RenderChain(this.renderer, this.scene, this.camera, toonShader, {
UI: this.UIContainer, UI: this.UIContainer,
shapes: this.shapesManager, shapes: this.shapesManager,

View File

@ -20,20 +20,20 @@ const CONTEXT = 'context';
const styles = { const styles = {
contextMenuContainer: { contextMenuContainer: {
position: 'absolute', position: 'absolute',
left: 0, left: 0,
bottom: 0, bottom: 0,
right: 0, right: 0,
top: 0, top: 0,
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
pointerEvents: 'none', /* enable clicking through object */ pointerEvents: 'none', /* enable clicking through object */
'& *': { '& *': {
pointerEvents: 'visible' /* enable clicking in children */ pointerEvents: 'visible' /* enable clicking in children */
} }
} }
} };
class SketcherToolbars extends React.Component { class SketcherToolbars extends React.Component {
@ -41,7 +41,8 @@ class SketcherToolbars extends React.Component {
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
toolbar2d: PropTypes.object, // TODO: specify further toolbar2d: PropTypes.object, // TODO: specify further
toolbar3d: PropTypes.object, // TODO: specify further toolbar3d: PropTypes.object, // TODO: specify further
context: PropTypes.object // TODO: specify further context: PropTypes.object, // TODO: specify further
classes: PropTypes.objectOf(PropTypes.string)
}; };
onSelect2D = ({ value }) => { onSelect2D = ({ value }) => {
const { dispatch } = this.props; const { dispatch } = this.props;

View File

@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Button from './Button.js'; import Button from './Button.js';
import Menu from './Menu.js'; import Menu from './Menu.js';
import bowser from 'bowser';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { hexToStyle } from '../utils/colorUtils.js'; import { hexToStyle } from '../utils/colorUtils.js';
// import createDebug from 'debug'; // import createDebug from 'debug';
@ -21,7 +20,9 @@ class SubMenu extends React.Component {
svg: PropTypes.string, svg: PropTypes.string,
children: PropTypes.node, children: PropTypes.node,
selectOnOpen: PropTypes.bool, selectOnOpen: PropTypes.bool,
toggleBehavior: PropTypes.bool toggleBehavior: PropTypes.bool,
color: PropTypes.number,
solid: PropTypes.bool
}; };
componentWillMount = () => { componentWillMount = () => {
// Listeners to close the submenu when anywhere else is clicked // Listeners to close the submenu when anywhere else is clicked

View File

@ -46,7 +46,7 @@ const toolbar3d = {
children: [ children: [
{ value: d3Tools.HEIGHT }, { value: d3Tools.HEIGHT },
{ value: d3Tools.SCULPT }, { value: d3Tools.SCULPT },
{ value: d3Tools.TWIST }, { value: d3Tools.TWIST }
// { value: d3Tools.STAMP } // { value: d3Tools.STAMP }
] ]
}; };

View File

@ -12,9 +12,9 @@ export default class MatcapMaterial extends THREE.ShaderMaterial {
constructor({ color = new THREE.Color(), opacity = 1 }) { constructor({ color = new THREE.Color(), opacity = 1 }) {
super({ super({
uniforms: { uniforms: {
"opacity": { type: 'f', value: opacity }, opacity: { type: 'f', value: opacity },
"tMatcap": { type: 't', value: matcapTexture }, tMatcap: { type: 't', value: matcapTexture },
"color": { type: 'vec3', value: new THREE.Vector3() } color: { type: 'vec3', value: new THREE.Vector3() }
}, },
vertexShader: matcapVert, vertexShader: matcapVert,
fragmentShader: matcapFrag fragmentShader: matcapFrag
@ -35,7 +35,8 @@ export default class MatcapMaterial extends THREE.ShaderMaterial {
set opacity(opacity) { set opacity(opacity) {
if (!this.uniforms) return opacity; if (!this.uniforms) return opacity;
return this.uniforms.opacity.value = opacity; this.uniforms.opacity.value = opacity;
return opacity;
} }
clone() { clone() {

12
src/d3/OutlinePass.js vendored
View File

@ -26,8 +26,8 @@ export default class OutlinePass {
this._edgeMaterial = new THREE.ShaderMaterial({ this._edgeMaterial = new THREE.ShaderMaterial({
uniforms: { uniforms: {
"tDiffuse": { type: 't', value: this._depthNormalRenderTarget.texture }, tDiffuse: { type: 't', value: this._depthNormalRenderTarget.texture },
"resolution": { type: 'v2', value: new THREE.Vector2() } resolution: { type: 'v2', value: new THREE.Vector2() }
}, },
vertexShader: edgeVert, vertexShader: edgeVert,
fragmentShader: edgeFrag fragmentShader: edgeFrag
@ -35,12 +35,12 @@ export default class OutlinePass {
this._copyEdge = new THREE.ShaderMaterial({ this._copyEdge = new THREE.ShaderMaterial({
uniforms: { uniforms: {
"tDiffuse": { type: 't', value: null }, tDiffuse: { type: 't', value: null },
"uTexArray" : { type: 'tv', value: [this._edgeRenderTarget.texture] } uTexArray : { type: 'tv', value: [this._edgeRenderTarget.texture] }
}, },
vertexShader: combineVert, vertexShader: combineVert,
fragmentShader: combineFrag fragmentShader: combineFrag
}) });
this._camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1); this._camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
this._scene = new THREE.Scene(); this._scene = new THREE.Scene();
@ -55,7 +55,7 @@ export default class OutlinePass {
this._edgeMaterial.uniforms.resolution.value.set(width, height); this._edgeMaterial.uniforms.resolution.value.set(width, height);
} }
render(renderer, writeBuffer, readBuffer, delta, maskActive) { render(renderer, writeBuffer, readBuffer) {
if (this._callbackBeforeRender) this._callbackBeforeRender(); if (this._callbackBeforeRender) this._callbackBeforeRender();
this._copyEdge.uniforms.tDiffuse.value = readBuffer.texture; this._copyEdge.uniforms.tDiffuse.value = readBuffer.texture;

View File

@ -52,13 +52,13 @@ export function createThrottle() {
if (!startLoop) return null; if (!startLoop) return null;
return function loop() { return (function loop() {
const promise = next().then(() => { const promise = next().then(() => {
if (typeof next === 'function') return loop(); if (typeof next === 'function') return loop();
}); });
next = true; next = true;
return promise; return promise;
}().then(() => { })().then(() => {
next = null; next = null;
}); });
}; };

View File

@ -20,7 +20,7 @@ export function getDbUrl(db) {
} else { } else {
return `${db.protocol}${db.host}`; return `${db.protocol}${db.host}`;
} }
}; }
const dbs = {}; const dbs = {};
export function getDb(dbUrl) { export function getDb(dbUrl) {

View File

@ -79,7 +79,10 @@ export function generateExportMesh(state, options = {}) {
}; };
for (const id in state.objectsById) { for (const id in state.objectsById) {
exportState.objectsById[id] = createExportShapeData(state.objectsById[id], offsetSingleWalls || unionGeometry, lineWidth); const shapeData = state.objectsById[id];
if (!SHAPE_TYPE_PROPERTIES[shapeData.type].D3Visible) continue;
const exportShapeData = createExportShapeData(shapeData, offsetSingleWalls || unionGeometry, lineWidth);
exportState.objectsById[id] = exportShapeData;
} }
const shapesManager = new ShapesManager({ toonShader: false }); const shapesManager = new ShapesManager({ toonShader: false });
@ -91,10 +94,11 @@ export function generateExportMesh(state, options = {}) {
const shapeData = exportState.objectsById[mesh.name]; const shapeData = exportState.objectsById[mesh.name];
if (mesh instanceof THREE.Mesh && shapeData.solid) { if (mesh instanceof THREE.Mesh && shapeData.solid) {
const { geometry, material } = mesh; const { geometry, material } = mesh;
const objectMatrix = state.spaces[shapeData.space].matrix;
let objectGeometry = geometry.clone(); let objectGeometry = geometry.clone();
objectGeometry.mergeVertices(); objectGeometry.mergeVertices();
objectGeometry.applyMatrix(new THREE.Matrix4().multiplyMatrices(state.spaces[shapeData.space].matrix, matrix)); objectGeometry.applyMatrix(new THREE.Matrix4().multiplyMatrices(objectMatrix, matrix));
const colorHex = material.color.getHex(); const colorHex = material.color.getHex();
let materialIndex = materials.findIndex(exportMaterial => exportMaterial.color.getHex() === colorHex); let materialIndex = materials.findIndex(exportMaterial => exportMaterial.color.getHex() === colorHex);
@ -149,7 +153,7 @@ export async function createFile(state, type, options) {
} }
case 'stl-blob': { case 'stl-blob': {
const buffer = exportSTL.fromMesh(exportMesh, true); const buffer = exportSTL.fromMesh(exportMesh, true);
return new Blob([buffer], { type: 'application/vnd.ms-pki.stl' }) return new Blob([buffer], { type: 'application/vnd.ms-pki.stl' });
} }
case 'obj-blob': { case 'obj-blob': {
const buffer = await exportOBJ.fromMesh(exportMesh); const buffer = await exportOBJ.fromMesh(exportMesh);

View File

@ -45,5 +45,5 @@ export function asyncValidateForm(dispatch, form, asyncValidate, formData) {
dispatch(stopAsyncValidation(form)); dispatch(stopAsyncValidation(form));
}).catch(error => { }).catch(error => {
dispatch(stopAsyncValidation(form, error)); dispatch(stopAsyncValidation(form, error));
}) });
} }

View File

@ -1,13 +1,13 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { shapeToPoints } from '../shape/shapeToPoints.js' import { shapeToPoints } from '../shape/shapeToPoints.js';
import { getPointsBounds } from '../shape/shapeDataUtils.js' import { getPointsBounds } from '../shape/shapeDataUtils.js';
import { Vector } from 'cal'; import { Vector } from 'cal';
import arrayMemoizer from './arrayMemoizer.js'; import arrayMemoizer from './arrayMemoizer.js';
import memoize from 'memoizee'; import memoize from 'memoizee';
// import createDebug from 'debug'; // import createDebug from 'debug';
// const debug = createDebug('d3d:util:selection'); // const debug = createDebug('d3d:util:selection');
// Memoized selector that returns the same array of shapeSata's when // Memoized selector that returns the same array of shapeData's when
// - the selection array didn't change // - the selection array didn't change
// - the objects in the resulting array didn't change // - the objects in the resulting array didn't change
// enables memoization of utils that use this array // enables memoization of utils that use this array

View File

@ -1,5 +1,5 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { loadImage } from './imageUtils.js' import { loadImage } from './imageUtils.js';
import createDebug from 'debug'; import createDebug from 'debug';
const debug = createDebug('d3d:threeUtils'); const debug = createDebug('d3d:threeUtils');

View File

@ -74,9 +74,7 @@ function floodFill(imageData, start, tolerance) {
for (let i = 0; i < neighbours.length; i ++) { for (let i = 0; i < neighbours.length; i ++) {
const neighbourIndex = neighbours[i]; const neighbourIndex = neighbours[i];
if (!done[neighbourIndex]) { if (!done[neighbourIndex]) stack.push(neighbourIndex);
stack.push(neighbourIndex);
}
done[neighbourIndex] = true; done[neighbourIndex] = true;
} }
} }