Add svg loader experiment.
This commit is contained in:
parent
543324851f
commit
60b13a9572
2640
libs/three_loaders/SVGLoader.js
Normal file
2640
libs/three_loaders/SVGLoader.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -437,3 +437,80 @@ OV.ImporterThree3mf = class extends OV.ImporterThreeBase
|
||||
return loadedObject;
|
||||
}
|
||||
};
|
||||
|
||||
OV.ImporterThreeSvg = class extends OV.ImporterThreeBase
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'svg';
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Z;
|
||||
}
|
||||
|
||||
GetExternalLibraries ()
|
||||
{
|
||||
return [
|
||||
'three_loaders/SVGLoader.js'
|
||||
];
|
||||
}
|
||||
|
||||
CreateLoader (manager)
|
||||
{
|
||||
return new THREE.SVGLoader (manager);
|
||||
}
|
||||
|
||||
GetMainObject (loadedObject)
|
||||
{
|
||||
function ShowFill (path)
|
||||
{
|
||||
const style = path.userData.style;
|
||||
if (style.fill === undefined || style.fill === 'none') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function ShowStroke (path)
|
||||
{
|
||||
const style = path.userData.style;
|
||||
if (style.stroke === undefined || style.stroke === 'none') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let object = new THREE.Object3D ();
|
||||
|
||||
const material = new THREE.MeshPhongMaterial ({
|
||||
color: 0xcc0000
|
||||
});
|
||||
for (let path of loadedObject.paths) {
|
||||
const shapes = THREE.SVGLoader.createShapes (path);
|
||||
if (ShowFill (path)) {
|
||||
for (const shape of shapes) {
|
||||
const geometry = new THREE.ShapeGeometry (shape);
|
||||
const mesh = new THREE.Mesh (geometry, material);
|
||||
object.add (mesh);
|
||||
}
|
||||
}
|
||||
if (ShowStroke (path)) {
|
||||
for (const subPath of path.subPaths) {
|
||||
const geometry = THREE.SVGLoader.pointsToStroke (subPath.getPoints (), path.userData.style);
|
||||
if (geometry) {
|
||||
const mesh = new THREE.Mesh (geometry, material);
|
||||
object.add (mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
@ -23,7 +23,8 @@ threeJsFileMap = [
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', '3MFLoader.js'), os.path.join ('three_loaders', '3MFLoader.js')],
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', 'ColladaLoader.js'), os.path.join ('three_loaders', 'ColladaLoader.js')],
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', 'FBXLoader.js'), os.path.join ('three_loaders', 'FBXLoader.js')],
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', 'VRMLLoader.js'), os.path.join ('three_loaders', 'VRMLLoader.js')]
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', 'VRMLLoader.js'), os.path.join ('three_loaders', 'VRMLLoader.js')],
|
||||
[os.path.join ('three', 'examples', 'js', 'loaders', 'SVGLoader.js'), os.path.join ('three_loaders', 'SVGLoader.js')]
|
||||
]
|
||||
|
||||
dracoFileMap = [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user