freeform-modeling-mcp 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/index.cjs +21 -0
- package/package.json +48 -0
- package/src/cli.ts +47 -0
- package/src/commands/start.ts +88 -0
- package/src/commands/status.ts +81 -0
- package/src/dev.ts +24 -0
- package/src/lib/fileproxy/index.ts +505 -0
- package/src/lib/fileproxy/proxy-server.js +347 -0
- package/src/lib/gltf2obj/compress.js +33 -0
- package/src/lib/gltf2obj/engine/core/core.js +34 -0
- package/src/lib/gltf2obj/engine/core/eventnotifier.js +39 -0
- package/src/lib/gltf2obj/engine/core/taskrunner.js +88 -0
- package/src/lib/gltf2obj/engine/export/exporter.js +38 -0
- package/src/lib/gltf2obj/engine/export/exporterbase.js +86 -0
- package/src/lib/gltf2obj/engine/export/exportermodel.js +117 -0
- package/src/lib/gltf2obj/engine/export/exporterobj.js +147 -0
- package/src/lib/gltf2obj/engine/geometry/box3d.js +60 -0
- package/src/lib/gltf2obj/engine/geometry/coord2d.js +35 -0
- package/src/lib/gltf2obj/engine/geometry/coord3d.js +126 -0
- package/src/lib/gltf2obj/engine/geometry/coord4d.js +15 -0
- package/src/lib/gltf2obj/engine/geometry/geometry.js +56 -0
- package/src/lib/gltf2obj/engine/geometry/matrix.js +440 -0
- package/src/lib/gltf2obj/engine/geometry/octree.js +160 -0
- package/src/lib/gltf2obj/engine/geometry/quaternion.js +83 -0
- package/src/lib/gltf2obj/engine/geometry/transformation.js +63 -0
- package/src/lib/gltf2obj/engine/geometry/tween.js +31 -0
- package/src/lib/gltf2obj/engine/import/importer.js +270 -0
- package/src/lib/gltf2obj/engine/import/importerbase.js +115 -0
- package/src/lib/gltf2obj/engine/import/importerfiles.js +139 -0
- package/src/lib/gltf2obj/engine/import/importergltf.js +1045 -0
- package/src/lib/gltf2obj/engine/import/importerutils.js +102 -0
- package/src/lib/gltf2obj/engine/io/binaryreader.js +93 -0
- package/src/lib/gltf2obj/engine/io/binarywriter.js +92 -0
- package/src/lib/gltf2obj/engine/io/bufferutils.js +85 -0
- package/src/lib/gltf2obj/engine/io/externallibs.js +42 -0
- package/src/lib/gltf2obj/engine/io/fileutils.js +120 -0
- package/src/lib/gltf2obj/engine/io/textwriter.js +41 -0
- package/src/lib/gltf2obj/engine/main.js +19 -0
- package/src/lib/gltf2obj/engine/model/color.js +130 -0
- package/src/lib/gltf2obj/engine/model/generator.js +433 -0
- package/src/lib/gltf2obj/engine/model/material.js +243 -0
- package/src/lib/gltf2obj/engine/model/mesh.js +173 -0
- package/src/lib/gltf2obj/engine/model/meshbuffer.js +233 -0
- package/src/lib/gltf2obj/engine/model/meshinstance.js +128 -0
- package/src/lib/gltf2obj/engine/model/meshutils.js +64 -0
- package/src/lib/gltf2obj/engine/model/model.js +195 -0
- package/src/lib/gltf2obj/engine/model/modelfinalization.js +377 -0
- package/src/lib/gltf2obj/engine/model/modelutils.js +117 -0
- package/src/lib/gltf2obj/engine/model/node.js +178 -0
- package/src/lib/gltf2obj/engine/model/object.js +90 -0
- package/src/lib/gltf2obj/engine/model/property.js +86 -0
- package/src/lib/gltf2obj/engine/model/quantities.js +46 -0
- package/src/lib/gltf2obj/engine/model/topology.js +139 -0
- package/src/lib/gltf2obj/engine/model/triangle.js +99 -0
- package/src/lib/gltf2obj/engine/threejs/threemodelloader.js +85 -0
- package/src/lib/gltf2obj/handler.js +63 -0
- package/src/lib/gltf2obj/index.js +47 -0
- package/src/lib/logger.ts +304 -0
- package/src/lib/print.ts +37 -0
- package/src/lib/utils.ts +34 -0
- package/src/lib/wsbridge/bridge.ts +639 -0
- package/src/lib/wsbridge/lock.ts +258 -0
- package/src/llmClient.ts +245 -0
- package/src/prompt.ts +187 -0
- package/src/server.ts +125 -0
- package/src/tools/assets-tool.ts +314 -0
- package/src/tools/basic-tools.ts +531 -0
- package/src/tools/index.ts +2 -0
- package/src/tools/material-tools.ts +88 -0
- package/src/tools/modeling/auxiliary-curve-tool.ts +44 -0
- package/src/tools/modeling/find-face.ts +38 -0
- package/src/tools/modeling/sweep-tool.ts +60 -0
- package/src/tools/modeling/utils.ts +181 -0
- package/src/tools/modeling-tools.ts +135 -0
- package/src/tools/screenshot-tools.ts +107 -0
- package/src/tools/tools-info.ts +107 -0
- package/src/tools/tripo3d-tools.ts +496 -0
- package/src/types/index.ts +25 -0
- package/src/types/tripo3d.ts +38 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { IsLower } from '../geometry/geometry.js';
|
|
2
|
+
import { PhongMaterial } from '../model/material.js';
|
|
3
|
+
import { RGBColor, IntegerToHexString } from '../model/color.js';
|
|
4
|
+
|
|
5
|
+
export function NameFromLine (line, startIndex, commentChar)
|
|
6
|
+
{
|
|
7
|
+
let name = line.substring (startIndex);
|
|
8
|
+
let commentStart = name.indexOf (commentChar);
|
|
9
|
+
if (commentStart !== -1) {
|
|
10
|
+
name = name.substring (0, commentStart);
|
|
11
|
+
}
|
|
12
|
+
return name.trim ();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ParametersFromLine (line, commentChar)
|
|
16
|
+
{
|
|
17
|
+
if (commentChar !== null) {
|
|
18
|
+
let commentStart = line.indexOf (commentChar);
|
|
19
|
+
if (commentStart !== -1) {
|
|
20
|
+
line = line.substring (0, commentStart).trim ();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return line.split (/\s+/u);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ReadLines (str, onLine)
|
|
27
|
+
{
|
|
28
|
+
function LineFound (line, onLine)
|
|
29
|
+
{
|
|
30
|
+
let trimmed = line.trim ();
|
|
31
|
+
if (trimmed.length > 0) {
|
|
32
|
+
onLine (trimmed);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let cursor = 0;
|
|
37
|
+
let next = str.indexOf ('\n', cursor);
|
|
38
|
+
while (next !== -1) {
|
|
39
|
+
LineFound (str.substring (cursor, next), onLine);
|
|
40
|
+
cursor = next + 1;
|
|
41
|
+
next = str.indexOf ('\n', cursor);
|
|
42
|
+
}
|
|
43
|
+
LineFound (str.substring (cursor), onLine);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function IsPowerOfTwo (x)
|
|
47
|
+
{
|
|
48
|
+
return (x & (x - 1)) === 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function NextPowerOfTwo (x)
|
|
52
|
+
{
|
|
53
|
+
if (IsPowerOfTwo (x)) {
|
|
54
|
+
return x;
|
|
55
|
+
}
|
|
56
|
+
let npot = Math.pow (2, Math.ceil (Math.log (x) / Math.log (2)));
|
|
57
|
+
return parseInt (npot, 10);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function UpdateMaterialTransparency (material)
|
|
61
|
+
{
|
|
62
|
+
material.transparent = false;
|
|
63
|
+
if (IsLower (material.opacity, 1.0)) {
|
|
64
|
+
material.transparent = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class ColorToMaterialConverter
|
|
69
|
+
{
|
|
70
|
+
constructor (model)
|
|
71
|
+
{
|
|
72
|
+
this.model = model;
|
|
73
|
+
this.colorToMaterialIndex = new Map ();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
GetMaterialIndex (r, g, b, a)
|
|
77
|
+
{
|
|
78
|
+
let colorKey =
|
|
79
|
+
IntegerToHexString (r) +
|
|
80
|
+
IntegerToHexString (g) +
|
|
81
|
+
IntegerToHexString (b);
|
|
82
|
+
let hasAlpha = (a !== undefined && a !== null);
|
|
83
|
+
if (hasAlpha) {
|
|
84
|
+
colorKey += IntegerToHexString (a);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (this.colorToMaterialIndex.has (colorKey)) {
|
|
88
|
+
return this.colorToMaterialIndex.get (colorKey);
|
|
89
|
+
} else {
|
|
90
|
+
let material = new PhongMaterial ();
|
|
91
|
+
material.name = colorKey.toUpperCase ();
|
|
92
|
+
material.color = new RGBColor (r, g, b);
|
|
93
|
+
if (hasAlpha && a < 255) {
|
|
94
|
+
material.opacity = a / 255.0;
|
|
95
|
+
UpdateMaterialTransparency (material);
|
|
96
|
+
}
|
|
97
|
+
let materialIndex = this.model.AddMaterial (material);
|
|
98
|
+
this.colorToMaterialIndex.set (colorKey, materialIndex);
|
|
99
|
+
return materialIndex;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export class BinaryReader {
|
|
2
|
+
constructor(arrayBuffer, isLittleEndian) {
|
|
3
|
+
this.arrayBuffer = arrayBuffer;
|
|
4
|
+
|
|
5
|
+
this.dataView = new DataView(arrayBuffer);
|
|
6
|
+
this.isLittleEndian = isLittleEndian;
|
|
7
|
+
this.position = 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
GetPosition () {
|
|
11
|
+
return this.position;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
SetPosition (position) {
|
|
15
|
+
this.position = position;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
GetByteLength () {
|
|
19
|
+
return this.arrayBuffer.byteLength;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Skip (bytes) {
|
|
23
|
+
this.position = this.position + bytes;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
End () {
|
|
27
|
+
return this.position >= this.arrayBuffer.byteLength;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ReadArrayBuffer (byteLength) {
|
|
31
|
+
let originalBufferView = new Uint8Array(this.arrayBuffer);
|
|
32
|
+
let arrayBuffer = new ArrayBuffer(byteLength);
|
|
33
|
+
let bufferView = new Uint8Array(arrayBuffer);
|
|
34
|
+
let subArray = originalBufferView.subarray(this.position, this.position + byteLength);
|
|
35
|
+
bufferView.set(subArray, 0);
|
|
36
|
+
this.position += byteLength;
|
|
37
|
+
return arrayBuffer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ReadBoolean8 () {
|
|
41
|
+
let result = this.dataView.getInt8(this.position);
|
|
42
|
+
this.position = this.position + 1;
|
|
43
|
+
return result ? true : false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
ReadCharacter8 () {
|
|
47
|
+
let result = this.dataView.getInt8(this.position);
|
|
48
|
+
this.position = this.position + 1;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
ReadUnsignedCharacter8 () {
|
|
53
|
+
let result = this.dataView.getUint8(this.position);
|
|
54
|
+
this.position = this.position + 1;
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ReadInteger16 () {
|
|
59
|
+
let result = this.dataView.getInt16(this.position, this.isLittleEndian);
|
|
60
|
+
this.position = this.position + 2;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ReadUnsignedInteger16 () {
|
|
65
|
+
let result = this.dataView.getUint16(this.position, this.isLittleEndian);
|
|
66
|
+
this.position = this.position + 2;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
ReadInteger32 () {
|
|
71
|
+
let result = this.dataView.getInt32(this.position, this.isLittleEndian);
|
|
72
|
+
this.position = this.position + 4;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ReadUnsignedInteger32 () {
|
|
77
|
+
let result = this.dataView.getUint32(this.position, this.isLittleEndian);
|
|
78
|
+
this.position = this.position + 4;
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ReadFloat32 () {
|
|
83
|
+
let result = this.dataView.getFloat32(this.position, this.isLittleEndian);
|
|
84
|
+
this.position = this.position + 4;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ReadDouble64 () {
|
|
89
|
+
let result = this.dataView.getFloat64(this.position, this.isLittleEndian);
|
|
90
|
+
this.position = this.position + 8;
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export class BinaryWriter
|
|
2
|
+
{
|
|
3
|
+
constructor (byteLength, isLittleEndian)
|
|
4
|
+
{
|
|
5
|
+
this.arrayBuffer = new ArrayBuffer (byteLength);
|
|
6
|
+
this.dataView = new DataView (this.arrayBuffer);
|
|
7
|
+
this.isLittleEndian = isLittleEndian;
|
|
8
|
+
this.position = 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
GetPosition ()
|
|
12
|
+
{
|
|
13
|
+
return this.position;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
SetPosition (position)
|
|
17
|
+
{
|
|
18
|
+
this.position = position;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
End ()
|
|
22
|
+
{
|
|
23
|
+
return this.position >= this.arrayBuffer.byteLength;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
GetBuffer ()
|
|
27
|
+
{
|
|
28
|
+
return this.arrayBuffer;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
WriteArrayBuffer (arrayBuffer)
|
|
32
|
+
{
|
|
33
|
+
let bufferView = new Uint8Array (arrayBuffer);
|
|
34
|
+
let thisBufferView = new Uint8Array (this.arrayBuffer);
|
|
35
|
+
thisBufferView.set (bufferView, this.position);
|
|
36
|
+
this.position += arrayBuffer.byteLength;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
WriteBoolean8 (val)
|
|
40
|
+
{
|
|
41
|
+
this.dataView.setInt8 (this.position, val ? 1 : 0);
|
|
42
|
+
this.position = this.position + 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
WriteCharacter8 (val)
|
|
46
|
+
{
|
|
47
|
+
this.dataView.setInt8 (this.position, val);
|
|
48
|
+
this.position = this.position + 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
WriteUnsignedCharacter8 (val)
|
|
52
|
+
{
|
|
53
|
+
this.dataView.setUint8 (this.position, val);
|
|
54
|
+
this.position = this.position + 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
WriteInteger16 (val)
|
|
58
|
+
{
|
|
59
|
+
this.dataView.setInt16 (this.position, val, this.isLittleEndian);
|
|
60
|
+
this.position = this.position + 2;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
WriteUnsignedInteger16 (val)
|
|
64
|
+
{
|
|
65
|
+
this.dataView.setUint16 (this.position, val, this.isLittleEndian);
|
|
66
|
+
this.position = this.position + 2;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
WriteInteger32 (val)
|
|
70
|
+
{
|
|
71
|
+
this.dataView.setInt32 (this.position, val, this.isLittleEndian);
|
|
72
|
+
this.position = this.position + 4;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
WriteUnsignedInteger32 (val)
|
|
76
|
+
{
|
|
77
|
+
this.dataView.setUint32 (this.position, val, this.isLittleEndian);
|
|
78
|
+
this.position = this.position + 4;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
WriteFloat32 (val)
|
|
82
|
+
{
|
|
83
|
+
this.dataView.setFloat32 (this.position, val, this.isLittleEndian);
|
|
84
|
+
this.position = this.position + 4;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
WriteDouble64 (val)
|
|
88
|
+
{
|
|
89
|
+
this.dataView.setFloat64 (this.position, val, this.isLittleEndian);
|
|
90
|
+
this.position = this.position + 8;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export function ArrayBufferToUtf8String (buffer) {
|
|
2
|
+
let decoder = new TextDecoder('utf-8');
|
|
3
|
+
return decoder.decode(buffer);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function ArrayBufferToAsciiString (buffer) {
|
|
7
|
+
let text = '';
|
|
8
|
+
let bufferView = new Uint8Array(buffer);
|
|
9
|
+
for (let i = 0; i < bufferView.byteLength; i++) {
|
|
10
|
+
text += String.fromCharCode(bufferView[i]);
|
|
11
|
+
}
|
|
12
|
+
return text;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function AsciiStringToArrayBuffer (str) {
|
|
16
|
+
let buffer = new ArrayBuffer(str.length);
|
|
17
|
+
let bufferView = new Uint8Array(buffer);
|
|
18
|
+
for (let i = 0; i < str.length; i++) {
|
|
19
|
+
bufferView[i] = str.charCodeAt(i);
|
|
20
|
+
}
|
|
21
|
+
return buffer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Utf8StringToArrayBuffer (str) {
|
|
25
|
+
let encoder = new TextEncoder();
|
|
26
|
+
let uint8Array = encoder.encode(str);
|
|
27
|
+
return uint8Array.buffer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function Base64DataURIToArrayBuffer (uri) {
|
|
31
|
+
let dataPrefix = 'data:';
|
|
32
|
+
if (!uri.startsWith(dataPrefix)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let mimeSeparator = uri.indexOf(';');
|
|
37
|
+
if (mimeSeparator === -1) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let bufferSeparator = uri.indexOf(',');
|
|
42
|
+
if (bufferSeparator === -1) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let mimeType = uri.substring(dataPrefix.length, dataPrefix.length + mimeSeparator - 5);
|
|
47
|
+
let base64String = atob(uri.substring(bufferSeparator + 1));
|
|
48
|
+
let buffer = new ArrayBuffer(base64String.length);
|
|
49
|
+
let bufferView = new Uint8Array(buffer);
|
|
50
|
+
for (let i = 0; i < base64String.length; i++) {
|
|
51
|
+
bufferView[i] = base64String.charCodeAt(i);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
mimeType: mimeType,
|
|
56
|
+
buffer: buffer
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function GetFileExtensionFromMimeType (mimeType) {
|
|
61
|
+
if (mimeType === undefined || mimeType === null) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
let mimeParts = mimeType.split('/');
|
|
65
|
+
if (mimeParts.length === 0) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
return mimeParts[mimeParts.length - 1];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function CreateObjectUrl (content) {
|
|
72
|
+
let blob = new Blob([content]);
|
|
73
|
+
let url = URL.createObjectURL(blob);
|
|
74
|
+
return url;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function CreateObjectUrlWithMimeType (content, mimeType) {
|
|
78
|
+
let blob = new Blob([content], { type: mimeType });
|
|
79
|
+
let url = URL.createObjectURL(blob);
|
|
80
|
+
return url;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function RevokeObjectUrl (url) {
|
|
84
|
+
URL.revokeObjectURL(url);
|
|
85
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let externalLibLocation = null;
|
|
2
|
+
let loadedExternalLibs = new Set ();
|
|
3
|
+
|
|
4
|
+
export function SetExternalLibLocation (newExternalLibLocation)
|
|
5
|
+
{
|
|
6
|
+
externalLibLocation = newExternalLibLocation;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function GetExternalLibPath (libName)
|
|
10
|
+
{
|
|
11
|
+
if (externalLibLocation === null) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return externalLibLocation + '/' + libName;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function LoadExternalLibrary (libName)
|
|
18
|
+
{
|
|
19
|
+
return new Promise ((resolve, reject) => {
|
|
20
|
+
if (externalLibLocation === null) {
|
|
21
|
+
reject ();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (loadedExternalLibs.has (libName)) {
|
|
26
|
+
resolve ();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let scriptElement = document.createElement ('script');
|
|
31
|
+
scriptElement.type = 'text/javascript';
|
|
32
|
+
scriptElement.src = GetExternalLibPath (libName);
|
|
33
|
+
scriptElement.onload = () => {
|
|
34
|
+
loadedExternalLibs.add (libName);
|
|
35
|
+
resolve ();
|
|
36
|
+
};
|
|
37
|
+
scriptElement.onerror = () => {
|
|
38
|
+
reject ();
|
|
39
|
+
};
|
|
40
|
+
document.head.appendChild (scriptElement);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export const FileSource =
|
|
5
|
+
{
|
|
6
|
+
Url: 1,
|
|
7
|
+
File: 2,
|
|
8
|
+
Decompressed: 3
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const FileFormat =
|
|
12
|
+
{
|
|
13
|
+
Text: 1,
|
|
14
|
+
Binary: 2
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function GetFileName(filePath) {
|
|
18
|
+
let firstSeparator = filePath.lastIndexOf('/');
|
|
19
|
+
if (firstSeparator === -1) {
|
|
20
|
+
firstSeparator = filePath.lastIndexOf('\\');
|
|
21
|
+
}
|
|
22
|
+
let fileName = filePath;
|
|
23
|
+
if (firstSeparator !== -1) {
|
|
24
|
+
fileName = filePath.substring(firstSeparator + 1);
|
|
25
|
+
}
|
|
26
|
+
let firstParamIndex = fileName.indexOf('?');
|
|
27
|
+
if (firstParamIndex !== -1) {
|
|
28
|
+
fileName = fileName.substring(0, firstParamIndex);
|
|
29
|
+
}
|
|
30
|
+
return decodeURI(fileName);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function GetFileExtension(filePath) {
|
|
34
|
+
let fileName = GetFileName(filePath);
|
|
35
|
+
let firstPoint = fileName.lastIndexOf('.');
|
|
36
|
+
if (firstPoint === -1) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
let extension = fileName.substring(firstPoint + 1);
|
|
40
|
+
return extension.toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function RequestUrl(url, onProgress) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
axios.get(url, {
|
|
46
|
+
responseType: 'arraybuffer',
|
|
47
|
+
onDownloadProgress: function (event) {
|
|
48
|
+
onProgress(event.loaded, event.total);
|
|
49
|
+
}
|
|
50
|
+
}).then(function (res) {
|
|
51
|
+
if (res.status == 200) {
|
|
52
|
+
const arrayBuffer = new ArrayBuffer(res.data.length);
|
|
53
|
+
var view = new Uint8Array(arrayBuffer);
|
|
54
|
+
view.set(res.data);
|
|
55
|
+
resolve(arrayBuffer);
|
|
56
|
+
} else {
|
|
57
|
+
reject();
|
|
58
|
+
}
|
|
59
|
+
}).catch(function (error) {
|
|
60
|
+
reject();
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toArrayBuffer(buf) {
|
|
66
|
+
var ab = new ArrayBuffer(buf.length);
|
|
67
|
+
var view = new Uint8Array(ab);
|
|
68
|
+
for (var i = 0; i < buf.length; ++i) {
|
|
69
|
+
view[i] = buf[i];
|
|
70
|
+
}
|
|
71
|
+
return ab;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function ReadFile(src, onProgress) {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
let readStream = fs.createReadStream(src)
|
|
77
|
+
let totalSize = fs.statSync(src).size
|
|
78
|
+
let curSize = 0
|
|
79
|
+
let arr = []
|
|
80
|
+
readStream.on('data', (chunk) => {
|
|
81
|
+
curSize += chunk.length
|
|
82
|
+
arr.push(chunk)
|
|
83
|
+
onProgress(curSize, totalSize);
|
|
84
|
+
})
|
|
85
|
+
readStream.on('end', () => {
|
|
86
|
+
resolve(Buffer.concat(arr, readStream.bytesRead))
|
|
87
|
+
})
|
|
88
|
+
readStream.on('error', (e) => {
|
|
89
|
+
reject();
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function TransformFileHostUrls(urls) {
|
|
95
|
+
for (let i = 0; i < urls.length; i++) {
|
|
96
|
+
let url = urls[i];
|
|
97
|
+
if (url.search(/www\.dropbox\.com/u) !== -1) {
|
|
98
|
+
url = url.replace('www.dropbox.com', 'dl.dropbox.com');
|
|
99
|
+
let separatorPos = url.indexOf('?');
|
|
100
|
+
if (separatorPos !== -1) {
|
|
101
|
+
url = url.substring(0, separatorPos);
|
|
102
|
+
}
|
|
103
|
+
urls[i] = url;
|
|
104
|
+
} else if (url.search(/github\.com/u) !== -1) {
|
|
105
|
+
url = url.replace('github.com', 'raw.githubusercontent.com');
|
|
106
|
+
url = url.replace('/blob', '');
|
|
107
|
+
let separatorPos = url.indexOf('?');
|
|
108
|
+
if (separatorPos !== -1) {
|
|
109
|
+
url = url.substring(0, separatorPos);
|
|
110
|
+
}
|
|
111
|
+
urls[i] = url;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function IsUrl(str) {
|
|
117
|
+
const regex = /^https?:\/\/\S+$/g;
|
|
118
|
+
const match = str.match(regex);
|
|
119
|
+
return match !== null;
|
|
120
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export class TextWriter
|
|
2
|
+
{
|
|
3
|
+
constructor ()
|
|
4
|
+
{
|
|
5
|
+
this.text = '';
|
|
6
|
+
this.indentation = 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
GetText ()
|
|
10
|
+
{
|
|
11
|
+
return this.text;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Indent (diff)
|
|
15
|
+
{
|
|
16
|
+
this.indentation += diff;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
WriteArrayLine (arr)
|
|
20
|
+
{
|
|
21
|
+
this.WriteLine (arr.join (' '));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
WriteLine (str)
|
|
25
|
+
{
|
|
26
|
+
this.WriteIndentation ();
|
|
27
|
+
this.Write (str + '\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
WriteIndentation ()
|
|
31
|
+
{
|
|
32
|
+
for (let i = 0; i < this.indentation; i++) {
|
|
33
|
+
this.Write (' ');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Write (str)
|
|
38
|
+
{
|
|
39
|
+
this.text += str;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { ImportSettings, ImportError, ImportResult, ImporterFileAccessor, Importer, ImportErrorCode } from './import/importer.js';
|
|
3
|
+
import { SetExternalLibLocation } from './io/externallibs.js';
|
|
4
|
+
import { GetFileName, GetFileExtension, RequestUrl, ReadFile, TransformFileHostUrls, IsUrl, FileSource, FileFormat } from './io/fileutils.js';
|
|
5
|
+
import { InputFile, ImporterFile, ImporterFileList, InputFilesFromUrls, InputFilesFromFileObjects } from './import/importerfiles.js';
|
|
6
|
+
import { ThreeModelLoader } from './threejs/threemodelloader.js';
|
|
7
|
+
import { Exporter } from './export/exporter.js';
|
|
8
|
+
import { ExporterSettings } from './export/exportermodel.js';
|
|
9
|
+
export {
|
|
10
|
+
|
|
11
|
+
ImportSettings, ImportError, ImportResult, ImporterFileAccessor, Importer, ImportErrorCode,
|
|
12
|
+
SetExternalLibLocation,
|
|
13
|
+
GetFileName, GetFileExtension, RequestUrl, ReadFile, TransformFileHostUrls, IsUrl, FileSource, FileFormat,
|
|
14
|
+
InputFile, ImporterFile, ImporterFileList, InputFilesFromUrls, InputFilesFromFileObjects,
|
|
15
|
+
ThreeModelLoader,
|
|
16
|
+
Exporter,
|
|
17
|
+
ExporterSettings
|
|
18
|
+
|
|
19
|
+
}
|