Use materials in svg importer.
This commit is contained in:
parent
d5a9c886e0
commit
19d49f3832
@ -38,45 +38,48 @@ OV.ImporterThreeSvg = class extends OV.ImporterThreeBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ShowStroke (path)
|
function GetOrCreateMaterial (materials, style, opacity)
|
||||||
{
|
{
|
||||||
const style = path.userData.style;
|
let material = null;
|
||||||
if (style.stroke === undefined || style.stroke === 'none') {
|
for (let existingMaterial of materials) {
|
||||||
return false;
|
if (existingMaterial.style === style && existingMaterial.opacity === opacity) {
|
||||||
|
material = existingMaterial.material;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
if (material === null) {
|
||||||
|
material = new THREE.MeshPhongMaterial ({
|
||||||
|
color: new THREE.Color ().setStyle (style),
|
||||||
|
opacity: opacity,
|
||||||
|
transparent: opacity < 1.0
|
||||||
|
});
|
||||||
|
materials.push ({
|
||||||
|
style : style,
|
||||||
|
opacity : opacity,
|
||||||
|
material : material
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let materials = [];
|
||||||
|
|
||||||
let object = new THREE.Object3D ();
|
let object = new THREE.Object3D ();
|
||||||
|
object.rotation.x = Math.PI;
|
||||||
|
|
||||||
let fillsObject = new THREE.Object3D ();
|
|
||||||
let strokesObject = new THREE.Object3D ();
|
|
||||||
|
|
||||||
fillsObject.name = 'Fills';
|
|
||||||
strokesObject.name = 'Strokes';
|
|
||||||
|
|
||||||
object.add (fillsObject);
|
|
||||||
object.add (strokesObject);
|
|
||||||
|
|
||||||
const material = new THREE.MeshPhongMaterial ({
|
|
||||||
color: 0xcc0000
|
|
||||||
});
|
|
||||||
for (let path of loadedObject.paths) {
|
for (let path of loadedObject.paths) {
|
||||||
const shapes = THREE.SVGLoader.createShapes (path);
|
const shapes = THREE.SVGLoader.createShapes (path);
|
||||||
if (ShowFill (path)) {
|
if (ShowFill (path)) {
|
||||||
|
let pathStyle = path.userData.style;
|
||||||
|
let pathMaterial = GetOrCreateMaterial (materials, pathStyle.fill, pathStyle.opacity);
|
||||||
for (const shape of shapes) {
|
for (const shape of shapes) {
|
||||||
const geometry = new THREE.ShapeGeometry (shape);
|
const geometry = new THREE.ExtrudeGeometry (shape, {
|
||||||
const mesh = new THREE.Mesh (geometry, material);
|
depth: 10,
|
||||||
fillsObject.add (mesh);
|
bevelEnabled: false
|
||||||
}
|
});
|
||||||
}
|
const mesh = new THREE.Mesh (geometry, pathMaterial);
|
||||||
if (ShowStroke (path)) {
|
mesh.name = path.userData.node.id;
|
||||||
for (const subPath of path.subPaths) {
|
object.add (mesh);
|
||||||
const geometry = THREE.SVGLoader.pointsToStroke (subPath.getPoints (), path.userData.style);
|
|
||||||
if (geometry) {
|
|
||||||
const mesh = new THREE.Mesh (geometry, material);
|
|
||||||
strokesObject.add (mesh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user