@needle-tools/engine 3.47.6 → 3.47.7

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.
@@ -12,16 +12,16 @@ export declare type FileType = "gltf" | "glb" | "vrm" | "fbx" | "obj" | "usdz" |
12
12
  * This method does perform a range request to the server to get the first few bytes of the file
13
13
  * If the file type can not be determined it will return "unknown"
14
14
  * @param url The URL of the file
15
- * @param lazy If true the file type will be determined by the file extension first - if the file extension is not known it will then check the header
15
+ * @param useExtension If true the file type will be determined by the file extension first - if the file extension is not known it will then check the header
16
16
  * @example
17
17
  * ```typescript
18
18
  * const url = "https://example.com/model.glb";
19
19
  * const fileType = await tryDetermineFileTypeFromURL(url);
20
20
  * console.log(fileType); // "glb"
21
21
  */
22
- export async function tryDetermineFileTypeFromURL(url: string, lazy: boolean = true): Promise<FileType> {
22
+ export async function tryDetermineFileTypeFromURL(url: string, useExtension: boolean = true): Promise<FileType> {
23
23
 
24
- if (lazy) {
24
+ if (useExtension) {
25
25
  // We want to save on requests so we first check the file extension if there's any
26
26
  // In some scenarios we might not have one (e.g. if we're dealing with blob: files or if the URL doesn't contain the filename)
27
27
  // In that case we need to check the header
@@ -37,6 +37,7 @@ export async function tryDetermineFileTypeFromURL(url: string, lazy: boolean = t
37
37
  if (!ext?.length) {
38
38
  ext = urlobj.pathname.split(".").pop()?.toUpperCase();
39
39
  }
40
+ console.debug("Use file extension to determine type: " + ext);
40
41
  switch (ext) {
41
42
  case "GLTF":
42
43
  return "gltf";
@@ -52,6 +53,8 @@ export async function tryDetermineFileTypeFromURL(url: string, lazy: boolean = t
52
53
  return "usda";
53
54
  case "USDZ":
54
55
  return "usdz";
56
+ case "OBJ":
57
+ return "obj";
55
58
  }
56
59
  }
57
60
 
@@ -94,29 +97,48 @@ export function tryDetermineFileTypeFromBinary(data: ArrayBuffer): FileType {
94
97
 
95
98
  // GLTF or GLB
96
99
  if (bytes[0] == 103 && bytes[1] == 108 && bytes[2] == 84 && bytes[3] == 70) {
100
+ console.debug("GLTF detected");
97
101
  return "glb";
98
102
  }
99
103
  // USDZ
100
104
  if (bytes[0] == 80 && bytes[1] == 75 && bytes[2] == 3 && bytes[3] == 4) {
105
+ console.debug("USDZ detected");
101
106
  return "usdz";
102
107
  }
103
108
  // USD
104
109
  if (bytes[0] == 80 && bytes[1] == 88 && bytes[2] == 82 && bytes[3] == 45 && bytes[4] == 85 && bytes[5] == 83 && bytes[6] == 68 && bytes[7] == 67) {
110
+ console.debug("Binary USD detected");
105
111
  return "usd";
106
112
  }
107
113
  // USDA: check if the file starts with #usda
108
- else if(bytes[0] == 35 && bytes[1] == 117 && bytes[2] == 115 && bytes[3] == 100 && bytes[4] == 97) {
114
+ else if (bytes[0] == 35 && bytes[1] == 117 && bytes[2] == 115 && bytes[3] == 100 && bytes[4] == 97) {
115
+ console.debug("ASCII USD detected");
109
116
  return "usda";
110
117
  }
111
118
  // FBX
112
119
  if (bytes[0] == 75 && bytes[1] == 97 && bytes[2] == 121 && bytes[3] == 100 && bytes[4] == 97 && bytes[5] == 114 && bytes[6] == 97 && bytes[7] == 32) {
120
+ console.debug("Binary FBX detected");
121
+ return "fbx";
122
+ }
123
+ // ASCII FBX
124
+ else if (bytes[0] == 59 && bytes[1] == 32 && bytes[2] == 70 && bytes[3] == 66 && bytes[4] == 88 && bytes[5] == 32) {
125
+ console.debug("ASCII FBX detected");
113
126
  return "fbx";
114
127
  }
115
128
  // OBJ - in this case exported from blender it starts with "# Blender" - we only check the first 10 bytes, technically it could still be a different file so we should do this check at the end
116
129
  else if (bytes[0] == 35 && bytes[1] == 32 && bytes[2] == 66 && bytes[3] == 108 && bytes[4] == 101 && bytes[5] == 110 && bytes[6] == 100 && bytes[7] == 101 && bytes[8] == 114 && bytes[9] == 32) {
117
- // const text = new TextDecoder().decode(data.slice(0, 9));
130
+ console.debug("OBJ detected");
118
131
  return "obj";
119
132
  }
133
+ // Check if it starts "# Alias OBJ"
134
+ else if (bytes[0] == 35 && bytes[1] == 32 && bytes[2] == 65 && bytes[3] == 108 && bytes[4] == 105 && bytes[5] == 97 && bytes[6] == 115 && bytes[7] == 32 && bytes[8] == 79 && bytes[9] == 66 && bytes[10] == 74) {
135
+ console.debug("OBJ detected");
136
+ return "obj";
137
+ }
138
+ else {
139
+ // const text = new TextDecoder().decode(data.slice(0, 9));
140
+ console.debug("Could not determine file type from binary data", bytes);
141
+ }
120
142
 
121
143
  // const text = new TextDecoder().decode(data);
122
144
  // if (text.startsWith("Kaydara FBX")) {
@@ -487,6 +487,7 @@ export class NeedleMenuElement extends HTMLElement {
487
487
  }
488
488
  .compact .options {
489
489
  flex-wrap: wrap;
490
+ gap: .3rem;
490
491
  }
491
492
  .compact .top .options {
492
493
  height: auto;
@@ -550,6 +551,7 @@ export class NeedleMenuElement extends HTMLElement {
550
551
  .compact .options > button {
551
552
  display: flex;
552
553
  flex-basis: 100%;
554
+ min-height: 3rem;
553
555
  }
554
556
  .compact .options > button.row2 {
555
557
  //border: 1px solid red !important;