New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@loaders.gl/obj

Package Overview
Dependencies
Maintainers
9
Versions
336
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/obj - npm Package Compare versions

Comparing version 4.2.0-alpha.6 to 4.2.0-beta.1

4

dist/dist.dev.js

@@ -601,2 +601,4 @@ (function webpackUniversalModuleDefinition(root, factory) {

var OBJLoader = {
dataType: null,
batchType: null,
name: "OBJ",

@@ -690,2 +692,4 @@ id: "obj",

var MTLLoader = {
dataType: null,
batchType: null,
name: "MTL",

@@ -692,0 +696,0 @@ id: "mtl",

6

dist/dist.min.js

@@ -7,9 +7,9 @@ (function webpackUniversalModuleDefinition(root, factory) {

else root['loaders'] = factory();})(globalThis, function () {
"use strict";var __exports__=(()=>{var U=Object.create;var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var P=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),X=(o,e)=>{for(var r in e)I(o,r,{get:e[r],enumerable:!0})},A=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!J.call(o,s)&&s!==r&&I(o,s,{get:()=>e[s],enumerable:!(t=z(e,s))||t.enumerable});return o},L=(o,e,r)=>(A(o,e,"default"),r&&A(r,e,"default")),G=(o,e,r)=>(r=o!=null?U(_(o)):{},A(e||!o||!o.__esModule?I(r,"default",{value:o,enumerable:!0}):r,o)),Y=o=>A(I({},"__esModule",{value:!0}),o);var V=P((ae,D)=>{D.exports=globalThis.loaders});var T={};X(T,{MTLLoader:()=>ne,OBJLoader:()=>oe,OBJWorkerLoader:()=>S});L(T,G(V(),1));function W(o,e="float32"){return o instanceof Date?"date-millisecond":o instanceof Number?e:typeof o=="string"?"utf8":(o===null||o==="undefined","null")}function O(o){let e=Z(o);return e!=="null"?{type:e,nullable:!1}:o.length>0?(e=W(o[0]),{type:e,nullable:!0}):{type:"null",nullable:!0}}function Z(o){switch(o.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function j(o){let e=1/0,r=1/0,t=1/0,s=-1/0,n=-1/0,l=-1/0,c=o.POSITION?o.POSITION.value:[],u=c&&c.length;for(let f=0;f<u;f+=3){let m=c[f],a=c[f+1],i=c[f+2];e=m<e?m:e,r=a<r?a:r,t=i<t?i:t,s=m>s?m:s,n=a>n?a:n,l=i>l?i:l}return[[e,r,t],[s,n,l]]}var Q=/^[og]\s*(.+)?/,$=/^mtllib /,q=/^usemtl /,v=class{constructor({index:e,name:r="",mtllib:t,smooth:s,groupStart:n}){this.index=e,this.name=r,this.mtllib=t,this.smooth=s,this.groupStart=n,this.groupEnd=-1,this.groupCount=-1,this.inherited=!1}clone(e=this.index){return new v({index:e,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0})}},k=class{constructor(e=""){this.name=e,this.geometry={vertices:[],normals:[],colors:[],uvs:[]},this.materials=[],this.smooth=!0,this.fromDeclaration=null}startMaterial(e,r){let t=this._finalize(!1);t&&(t.inherited||t.groupCount<=0)&&this.materials.splice(t.index,1);let s=new v({index:this.materials.length,name:e,mtllib:Array.isArray(r)&&r.length>0?r[r.length-1]:"",smooth:t!==void 0?t.smooth:this.smooth,groupStart:t!==void 0?t.groupEnd:0});return this.materials.push(s),s}currentMaterial(){if(this.materials.length>0)return this.materials[this.materials.length-1]}_finalize(e){let r=this.currentMaterial();if(r&&r.groupEnd===-1&&(r.groupEnd=this.geometry.vertices.length/3,r.groupCount=r.groupEnd-r.groupStart,r.inherited=!1),e&&this.materials.length>1)for(let t=this.materials.length-1;t>=0;t--)this.materials[t].groupCount<=0&&this.materials.splice(t,1);return e&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),r}},w=class{constructor(){this.objects=[],this.object=null,this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.materialLibraries=[],this.startObject("",!1)}startObject(e,r=!0){if(this.object&&!this.object.fromDeclaration){this.object.name=e,this.object.fromDeclaration=r;return}let t=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object=new k(e),this.object.fromDeclaration=r,t&&t.name&&typeof t.clone=="function"){let s=t.clone(0);s.inherited=!0,this.object.materials.push(s)}this.objects.push(this.object)}finalize(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)}parseVertexIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/3)*3}parseNormalIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/3)*3}parseUVIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/2)*2}addVertex(e,r,t){let s=this.vertices,n=this.object.geometry.vertices;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addVertexPoint(e){let r=this.vertices;this.object.geometry.vertices.push(r[e+0],r[e+1],r[e+2])}addVertexLine(e){let r=this.vertices;this.object.geometry.vertices.push(r[e+0],r[e+1],r[e+2])}addNormal(e,r,t){let s=this.normals,n=this.object.geometry.normals;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addColor(e,r,t){let s=this.colors,n=this.object.geometry.colors;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addUV(e,r,t){let s=this.uvs,n=this.object.geometry.uvs;n.push(s[e+0],s[e+1]),n.push(s[r+0],s[r+1]),n.push(s[t+0],s[t+1])}addUVLine(e){let r=this.uvs;this.object.geometry.uvs.push(r[e+0],r[e+1])}addFace(e,r,t,s,n,l,c,u,f){let m=this.vertices.length,a=this.parseVertexIndex(e,m),i=this.parseVertexIndex(r,m),h=this.parseVertexIndex(t,m);if(this.addVertex(a,i,h),s!==void 0&&s!==""){let p=this.uvs.length;a=this.parseUVIndex(s,p),i=this.parseUVIndex(n,p),h=this.parseUVIndex(l,p),this.addUV(a,i,h)}if(c!==void 0&&c!==""){let p=this.normals.length;a=this.parseNormalIndex(c,p),i=c===u?a:this.parseNormalIndex(u,p),h=c===f?a:this.parseNormalIndex(f,p),this.addNormal(a,i,h)}this.colors.length>0&&this.addColor(a,i,h)}addPointGeometry(e){this.object.geometry.type="Points";let r=this.vertices.length;for(let t of e)this.addVertexPoint(this.parseVertexIndex(t,r))}addLineGeometry(e,r){this.object.geometry.type="Line";let t=this.vertices.length,s=this.uvs.length;for(let n of e)this.addVertexLine(this.parseVertexIndex(n,t));for(let n of r)this.addUVLine(this.parseUVIndex(n,s))}};function R(o){let e=new w;o.indexOf(`\r
"use strict";var __exports__=(()=>{var U=Object.create;var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var P=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),X=(o,e)=>{for(var r in e)I(o,r,{get:e[r],enumerable:!0})},A=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!J.call(o,s)&&s!==r&&I(o,s,{get:()=>e[s],enumerable:!(t=z(e,s))||t.enumerable});return o},L=(o,e,r)=>(A(o,e,"default"),r&&A(r,e,"default")),G=(o,e,r)=>(r=o!=null?U(_(o)):{},A(e||!o||!o.__esModule?I(r,"default",{value:o,enumerable:!0}):r,o)),Y=o=>A(I({},"__esModule",{value:!0}),o);var V=P((ae,D)=>{D.exports=globalThis.loaders});var v={};X(v,{MTLLoader:()=>ne,OBJLoader:()=>oe,OBJWorkerLoader:()=>S});L(v,G(V(),1));function W(o,e="float32"){return o instanceof Date?"date-millisecond":o instanceof Number?e:typeof o=="string"?"utf8":(o===null||o==="undefined","null")}function O(o){let e=Z(o);return e!=="null"?{type:e,nullable:!1}:o.length>0?(e=W(o[0]),{type:e,nullable:!0}):{type:"null",nullable:!0}}function Z(o){switch(o.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function j(o){let e=1/0,r=1/0,t=1/0,s=-1/0,n=-1/0,l=-1/0,c=o.POSITION?o.POSITION.value:[],u=c&&c.length;for(let f=0;f<u;f+=3){let m=c[f],a=c[f+1],i=c[f+2];e=m<e?m:e,r=a<r?a:r,t=i<t?i:t,s=m>s?m:s,n=a>n?a:n,l=i>l?i:l}return[[e,r,t],[s,n,l]]}var Q=/^[og]\s*(.+)?/,$=/^mtllib /,q=/^usemtl /,T=class{constructor({index:e,name:r="",mtllib:t,smooth:s,groupStart:n}){this.index=e,this.name=r,this.mtllib=t,this.smooth=s,this.groupStart=n,this.groupEnd=-1,this.groupCount=-1,this.inherited=!1}clone(e=this.index){return new T({index:e,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0})}},k=class{constructor(e=""){this.name=e,this.geometry={vertices:[],normals:[],colors:[],uvs:[]},this.materials=[],this.smooth=!0,this.fromDeclaration=null}startMaterial(e,r){let t=this._finalize(!1);t&&(t.inherited||t.groupCount<=0)&&this.materials.splice(t.index,1);let s=new T({index:this.materials.length,name:e,mtllib:Array.isArray(r)&&r.length>0?r[r.length-1]:"",smooth:t!==void 0?t.smooth:this.smooth,groupStart:t!==void 0?t.groupEnd:0});return this.materials.push(s),s}currentMaterial(){if(this.materials.length>0)return this.materials[this.materials.length-1]}_finalize(e){let r=this.currentMaterial();if(r&&r.groupEnd===-1&&(r.groupEnd=this.geometry.vertices.length/3,r.groupCount=r.groupEnd-r.groupStart,r.inherited=!1),e&&this.materials.length>1)for(let t=this.materials.length-1;t>=0;t--)this.materials[t].groupCount<=0&&this.materials.splice(t,1);return e&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),r}},w=class{constructor(){this.objects=[],this.object=null,this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.materialLibraries=[],this.startObject("",!1)}startObject(e,r=!0){if(this.object&&!this.object.fromDeclaration){this.object.name=e,this.object.fromDeclaration=r;return}let t=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object=new k(e),this.object.fromDeclaration=r,t&&t.name&&typeof t.clone=="function"){let s=t.clone(0);s.inherited=!0,this.object.materials.push(s)}this.objects.push(this.object)}finalize(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)}parseVertexIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/3)*3}parseNormalIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/3)*3}parseUVIndex(e,r){let t=parseInt(e);return(t>=0?t-1:t+r/2)*2}addVertex(e,r,t){let s=this.vertices,n=this.object.geometry.vertices;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addVertexPoint(e){let r=this.vertices;this.object.geometry.vertices.push(r[e+0],r[e+1],r[e+2])}addVertexLine(e){let r=this.vertices;this.object.geometry.vertices.push(r[e+0],r[e+1],r[e+2])}addNormal(e,r,t){let s=this.normals,n=this.object.geometry.normals;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addColor(e,r,t){let s=this.colors,n=this.object.geometry.colors;n.push(s[e+0],s[e+1],s[e+2]),n.push(s[r+0],s[r+1],s[r+2]),n.push(s[t+0],s[t+1],s[t+2])}addUV(e,r,t){let s=this.uvs,n=this.object.geometry.uvs;n.push(s[e+0],s[e+1]),n.push(s[r+0],s[r+1]),n.push(s[t+0],s[t+1])}addUVLine(e){let r=this.uvs;this.object.geometry.uvs.push(r[e+0],r[e+1])}addFace(e,r,t,s,n,l,c,u,f){let m=this.vertices.length,a=this.parseVertexIndex(e,m),i=this.parseVertexIndex(r,m),h=this.parseVertexIndex(t,m);if(this.addVertex(a,i,h),s!==void 0&&s!==""){let p=this.uvs.length;a=this.parseUVIndex(s,p),i=this.parseUVIndex(n,p),h=this.parseUVIndex(l,p),this.addUV(a,i,h)}if(c!==void 0&&c!==""){let p=this.normals.length;a=this.parseNormalIndex(c,p),i=c===u?a:this.parseNormalIndex(u,p),h=c===f?a:this.parseNormalIndex(f,p),this.addNormal(a,i,h)}this.colors.length>0&&this.addColor(a,i,h)}addPointGeometry(e){this.object.geometry.type="Points";let r=this.vertices.length;for(let t of e)this.addVertexPoint(this.parseVertexIndex(t,r))}addLineGeometry(e,r){this.object.geometry.type="Line";let t=this.vertices.length,s=this.uvs.length;for(let n of e)this.addVertexLine(this.parseVertexIndex(n,t));for(let n of r)this.addUVLine(this.parseUVIndex(n,s))}};function R(o){let e=new w;o.indexOf(`\r
`)!==-1&&(o=o.replace(/\r\n/g,`
`)),o.indexOf(`\\
`)!==-1&&(o=o.replace(/\\\n/g,""));let r=o.split(`
`),t="",s="",n=0,l=[],c=typeof"".trimLeft=="function";for(let m=0,a=r.length;m<a;m++)if(t=r[m],t=c?t.trimLeft():t.trim(),n=t.length,n!==0&&(s=t.charAt(0),s!=="#"))if(s==="v"){let i=t.split(/\s+/);switch(i[0]){case"v":e.vertices.push(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3])),i.length>=7&&e.colors.push(parseFloat(i[4]),parseFloat(i[5]),parseFloat(i[6]));break;case"vn":e.normals.push(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3]));break;case"vt":e.uvs.push(parseFloat(i[1]),parseFloat(i[2]));break;default:}}else if(s==="f"){let h=t.substr(1).trim().split(/\s+/),p=[];for(let d=0,g=h.length;d<g;d++){let y=h[d];if(y.length>0){let x=y.split("/");p.push(x)}}let b=p[0];for(let d=1,g=p.length-1;d<g;d++){let y=p[d],x=p[d+1];e.addFace(b[0],y[0],x[0],b[1],y[1],x[1],b[2],y[2],x[2])}}else if(s==="l"){let i=t.substring(1).trim().split(" "),h,p=[];if(t.indexOf("/")===-1)h=i;else{h=[];for(let b=0,d=i.length;b<d;b++){let g=i[b].split("/");g[0]!==""&&h.push(g[0]),g[1]!==""&&p.push(g[1])}}e.addLineGeometry(h,p)}else if(s==="p"){let h=t.substr(1).trim().split(" ");e.addPointGeometry(h)}else if((l=Q.exec(t))!==null){let i=(" "+l[0].substr(1).trim()).substr(1);e.startObject(i)}else if(q.test(t))e.object.startMaterial(t.substring(7).trim(),e.materialLibraries);else if($.test(t))e.materialLibraries.push(t.substring(7).trim());else if(s==="s"){if(l=t.split(" "),l.length>1){let h=l[1].trim().toLowerCase();e.object.smooth=h!=="0"&&h!=="off"}else e.object.smooth=!0;let i=e.object.currentMaterial();i&&(i.smooth=e.object.smooth)}else{if(t==="\0")continue;throw new Error(`Unexpected line: "${t}"`)}e.finalize();let u=[],f=[];for(let m of e.objects){let{geometry:a}=m;if(a.vertices.length===0)continue;let i={header:{vertexCount:a.vertices.length/3},attributes:{}};switch(a.type){case"Points":i.mode=0;break;case"Line":i.mode=1;break;default:i.mode=4;break}i.attributes.POSITION={value:new Float32Array(a.vertices),size:3},a.normals.length>0&&(i.attributes.NORMAL={value:new Float32Array(a.normals),size:3}),a.colors.length>0&&(i.attributes.COLOR_0={value:new Float32Array(a.colors),size:3}),a.uvs.length>0&&(i.attributes.TEXCOORD_0={value:new Float32Array(a.uvs),size:2}),i.materials=[];for(let h of m.materials){let p={name:h.name,flatShading:!h.smooth};i.materials.push(p),f.push(p)}i.name=m.name,u.push(i)}return{meshes:u,materials:f}}function C(o,e={}){let r={};for(let s in e)s!=="value"&&(r[s]=JSON.stringify(e[s]));let t=[];for(let s in o){let n=o[s],l=H(s,n);t.push(l)}return{fields:t,metadata:r}}function H(o,e){let r={};for(let n in e)n!=="value"&&(r[n]=JSON.stringify(e[n]));let{type:t}=O(e.value);return e.size===1||e.size===void 0||(t={type:"fixed-size-list",listSize:e.size,children:[{name:"values",type:t}]}),{name:o,type:t,nullable:!1,metadata:r}}function M(o,e){let{meshes:r}=R(o),t=r.reduce((c,u)=>c+u.header.vertexCount,0),s=K(r,t),n={vertexCount:t,boundingBox:j(s)},l=C(s,{mode:4,boundingBox:n.boundingBox});return{loaderData:{header:{}},schema:l,header:n,mode:4,topology:"point-list",attributes:s}}function K(o,e){let r=new Float32Array(e*3),t,s,n,l=0;for(let u of o){let{POSITION:f,NORMAL:m,COLOR_0:a,TEXCOORD_0:i}=u.attributes;r.set(f.value,l*3),m&&(t=t||new Float32Array(e*3),t.set(m.value,l*3)),a&&(s=s||new Float32Array(e*3),s.set(a.value,l*3)),i&&(n=n||new Float32Array(e*2),n.set(i.value,l*2)),l+=f.value.length/3}let c={};return c.POSITION={value:r,size:3},t&&(c.NORMAL={value:t,size:3}),s&&(c.COLOR_0={value:s,size:3}),n&&(c.TEXCOORD_0={value:n,size:2}),c}var ee="4.2.0-alpha.5",S={name:"OBJ",id:"obj",module:"obj",version:ee,worker:!0,extensions:["obj"],mimeTypes:["text/plain"],testText:te,options:{obj:{}}};function te(o){return o[0]==="v"}var re=/\s+/;function B(o,e){let r=[],t={name:"placeholder"},s=o.split(`
`);for(let n of s){if(n=n.trim(),n.length===0||n.charAt(0)==="#")continue;let l=n.indexOf(" "),c=l>=0?n.substring(0,l):n;c=c.toLowerCase();let u=l>=0?n.substring(l+1):"";switch(u=u.trim(),c){case"newmtl":t={name:u},r.push(t);break;case"ka":t.ambientColor=F(u);break;case"kd":t.diffuseColor=F(u);break;case"map_kd":t.diffuseTextureUrl=u;break;case"ks":t.specularColor=F(u);break;case"map_ks":t.specularTextureUrl=u;break;case"ke":t.emissiveColor=F(u);break;case"map_ke":t.emissiveTextureUrl=u;break;case"ns":t.shininess=parseFloat(u);break;case"map_ns":break;case"ni":t.refraction=parseFloat(u);break;case"illum":t.illumination=parseFloat(u);break;default:break}}return r}function F(o,e){let r=o.split(re,3);return[parseFloat(r[0]),parseFloat(r[1]),parseFloat(r[2])]}var se="4.2.0-alpha.5",N={name:"MTL",id:"mtl",module:"mtl",version:se,worker:!0,extensions:["mtl"],mimeTypes:["text/plain"],testText:o=>o.includes("newmtl"),options:{mtl:{}}};var oe={...S,parse:async(o,e)=>M(new TextDecoder().decode(o),e),parseTextSync:(o,e)=>M(o,e)},ne={...N,parse:async(o,e)=>B(new TextDecoder().decode(o),e?.mtl),parseTextSync:(o,e)=>B(o,e?.mtl)};return Y(T);})();
`),t="",s="",n=0,l=[],c=typeof"".trimLeft=="function";for(let m=0,a=r.length;m<a;m++)if(t=r[m],t=c?t.trimLeft():t.trim(),n=t.length,n!==0&&(s=t.charAt(0),s!=="#"))if(s==="v"){let i=t.split(/\s+/);switch(i[0]){case"v":e.vertices.push(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3])),i.length>=7&&e.colors.push(parseFloat(i[4]),parseFloat(i[5]),parseFloat(i[6]));break;case"vn":e.normals.push(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3]));break;case"vt":e.uvs.push(parseFloat(i[1]),parseFloat(i[2]));break;default:}}else if(s==="f"){let h=t.substr(1).trim().split(/\s+/),p=[];for(let d=0,g=h.length;d<g;d++){let y=h[d];if(y.length>0){let x=y.split("/");p.push(x)}}let b=p[0];for(let d=1,g=p.length-1;d<g;d++){let y=p[d],x=p[d+1];e.addFace(b[0],y[0],x[0],b[1],y[1],x[1],b[2],y[2],x[2])}}else if(s==="l"){let i=t.substring(1).trim().split(" "),h,p=[];if(t.indexOf("/")===-1)h=i;else{h=[];for(let b=0,d=i.length;b<d;b++){let g=i[b].split("/");g[0]!==""&&h.push(g[0]),g[1]!==""&&p.push(g[1])}}e.addLineGeometry(h,p)}else if(s==="p"){let h=t.substr(1).trim().split(" ");e.addPointGeometry(h)}else if((l=Q.exec(t))!==null){let i=(" "+l[0].substr(1).trim()).substr(1);e.startObject(i)}else if(q.test(t))e.object.startMaterial(t.substring(7).trim(),e.materialLibraries);else if($.test(t))e.materialLibraries.push(t.substring(7).trim());else if(s==="s"){if(l=t.split(" "),l.length>1){let h=l[1].trim().toLowerCase();e.object.smooth=h!=="0"&&h!=="off"}else e.object.smooth=!0;let i=e.object.currentMaterial();i&&(i.smooth=e.object.smooth)}else{if(t==="\0")continue;throw new Error(`Unexpected line: "${t}"`)}e.finalize();let u=[],f=[];for(let m of e.objects){let{geometry:a}=m;if(a.vertices.length===0)continue;let i={header:{vertexCount:a.vertices.length/3},attributes:{}};switch(a.type){case"Points":i.mode=0;break;case"Line":i.mode=1;break;default:i.mode=4;break}i.attributes.POSITION={value:new Float32Array(a.vertices),size:3},a.normals.length>0&&(i.attributes.NORMAL={value:new Float32Array(a.normals),size:3}),a.colors.length>0&&(i.attributes.COLOR_0={value:new Float32Array(a.colors),size:3}),a.uvs.length>0&&(i.attributes.TEXCOORD_0={value:new Float32Array(a.uvs),size:2}),i.materials=[];for(let h of m.materials){let p={name:h.name,flatShading:!h.smooth};i.materials.push(p),f.push(p)}i.name=m.name,u.push(i)}return{meshes:u,materials:f}}function C(o,e={}){let r={};for(let s in e)s!=="value"&&(r[s]=JSON.stringify(e[s]));let t=[];for(let s in o){let n=o[s],l=H(s,n);t.push(l)}return{fields:t,metadata:r}}function H(o,e){let r={};for(let n in e)n!=="value"&&(r[n]=JSON.stringify(e[n]));let{type:t}=O(e.value);return e.size===1||e.size===void 0||(t={type:"fixed-size-list",listSize:e.size,children:[{name:"values",type:t}]}),{name:o,type:t,nullable:!1,metadata:r}}function M(o,e){let{meshes:r}=R(o),t=r.reduce((c,u)=>c+u.header.vertexCount,0),s=K(r,t),n={vertexCount:t,boundingBox:j(s)},l=C(s,{mode:4,boundingBox:n.boundingBox});return{loaderData:{header:{}},schema:l,header:n,mode:4,topology:"point-list",attributes:s}}function K(o,e){let r=new Float32Array(e*3),t,s,n,l=0;for(let u of o){let{POSITION:f,NORMAL:m,COLOR_0:a,TEXCOORD_0:i}=u.attributes;r.set(f.value,l*3),m&&(t=t||new Float32Array(e*3),t.set(m.value,l*3)),a&&(s=s||new Float32Array(e*3),s.set(a.value,l*3)),i&&(n=n||new Float32Array(e*2),n.set(i.value,l*2)),l+=f.value.length/3}let c={};return c.POSITION={value:r,size:3},t&&(c.NORMAL={value:t,size:3}),s&&(c.COLOR_0={value:s,size:3}),n&&(c.TEXCOORD_0={value:n,size:2}),c}var ee="4.2.0-alpha.6",S={dataType:null,batchType:null,name:"OBJ",id:"obj",module:"obj",version:ee,worker:!0,extensions:["obj"],mimeTypes:["text/plain"],testText:te,options:{obj:{}}};function te(o){return o[0]==="v"}var re=/\s+/;function B(o,e){let r=[],t={name:"placeholder"},s=o.split(`
`);for(let n of s){if(n=n.trim(),n.length===0||n.charAt(0)==="#")continue;let l=n.indexOf(" "),c=l>=0?n.substring(0,l):n;c=c.toLowerCase();let u=l>=0?n.substring(l+1):"";switch(u=u.trim(),c){case"newmtl":t={name:u},r.push(t);break;case"ka":t.ambientColor=F(u);break;case"kd":t.diffuseColor=F(u);break;case"map_kd":t.diffuseTextureUrl=u;break;case"ks":t.specularColor=F(u);break;case"map_ks":t.specularTextureUrl=u;break;case"ke":t.emissiveColor=F(u);break;case"map_ke":t.emissiveTextureUrl=u;break;case"ns":t.shininess=parseFloat(u);break;case"map_ns":break;case"ni":t.refraction=parseFloat(u);break;case"illum":t.illumination=parseFloat(u);break;default:break}}return r}function F(o,e){let r=o.split(re,3);return[parseFloat(r[0]),parseFloat(r[1]),parseFloat(r[2])]}var se="4.2.0-alpha.6",N={dataType:null,batchType:null,name:"MTL",id:"mtl",module:"mtl",version:se,worker:!0,extensions:["mtl"],mimeTypes:["text/plain"],testText:o=>o.includes("newmtl"),options:{mtl:{}}};var oe={...S,parse:async(o,e)=>M(new TextDecoder().decode(o),e),parseTextSync:(o,e)=>M(o,e)},ne={...N,parse:async(o,e)=>B(new TextDecoder().decode(o),e?.mtl),parseTextSync:(o,e)=>B(o,e?.mtl)};return Y(v);})();
return __exports__;
});

@@ -1,2 +0,1 @@

import type { LoaderWithParser } from '@loaders.gl/loader-utils';
import type { Mesh } from '@loaders.gl/schema';

@@ -7,2 +6,3 @@ import type { OBJLoaderOptions } from "./obj-loader.js";

import type { MTLLoaderOptions } from "./mtl-loader.js";
export type { OBJLoaderOptions } from "./obj-loader.js";
export { OBJWorkerLoader };

@@ -12,7 +12,39 @@ /**

*/
export declare const OBJLoader: LoaderWithParser<Mesh, never, OBJLoaderOptions>;
export declare const OBJLoader: {
readonly parse: (arrayBuffer: ArrayBuffer, options?: OBJLoaderOptions) => Promise<Mesh>;
readonly parseTextSync: (text: string, options?: OBJLoaderOptions) => Mesh;
readonly dataType: Mesh;
readonly batchType: never;
readonly name: "OBJ";
readonly id: "obj";
readonly module: "obj";
readonly version: any;
readonly worker: true;
readonly extensions: ["obj"];
readonly mimeTypes: ["text/plain"];
readonly testText: (text: string) => boolean;
readonly options: {
readonly obj: {};
};
};
/**
* Loader for the MTL material format
*/
export declare const MTLLoader: LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions>;
export declare const MTLLoader: {
readonly parse: (arrayBuffer: ArrayBuffer, options?: MTLLoaderOptions) => Promise<MTLMaterial[]>;
readonly parseTextSync: (text: string, options?: MTLLoaderOptions) => MTLMaterial[];
readonly dataType: MTLMaterial[];
readonly batchType: never;
readonly name: "MTL";
readonly id: "mtl";
readonly module: "mtl";
readonly version: any;
readonly worker: true;
readonly extensions: ["mtl"];
readonly mimeTypes: ["text/plain"];
readonly testText: (text: string) => boolean;
readonly options: {
readonly mtl: {};
};
};
//# sourceMappingURL=index.d.ts.map

@@ -0,1 +1,4 @@

// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright vis.gl contributors
import { parseOBJ } from "./lib/parse-obj.js";

@@ -5,3 +8,2 @@ import { OBJLoader as OBJWorkerLoader } from "./obj-loader.js";

import { MTLLoader as MTLWorkerLoader } from "./mtl-loader.js";
// OBJLoader
export { OBJWorkerLoader };

@@ -8,0 +10,0 @@ /**

@@ -1,2 +0,2 @@

import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
import type { LoaderOptions } from '@loaders.gl/loader-utils';
import type { MTLMaterial, ParseMTLOptions } from "./lib/parse-mtl.js";

@@ -10,3 +10,17 @@ export type MTLLoaderOptions = LoaderOptions & {

*/
export declare const MTLLoader: Loader<MTLMaterial[], never, LoaderOptions>;
export declare const MTLLoader: {
readonly dataType: MTLMaterial[];
readonly batchType: never;
readonly name: "MTL";
readonly id: "mtl";
readonly module: "mtl";
readonly version: any;
readonly worker: true;
readonly extensions: ["mtl"];
readonly mimeTypes: ["text/plain"];
readonly testText: (text: string) => boolean;
readonly options: {
readonly mtl: {};
};
};
//# sourceMappingURL=mtl-loader.d.ts.map
// __VERSION__ is injected by babel-plugin-version-inline
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
const VERSION = typeof "4.2.0-alpha.6" !== 'undefined' ? "4.2.0-alpha.6" : 'latest';
/**

@@ -9,2 +9,4 @@ * Loader for the MTL material format

export const MTLLoader = {
dataType: null,
batchType: null,
name: 'MTL',

@@ -11,0 +13,0 @@ id: 'mtl',

@@ -1,5 +0,8 @@

import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
import type { LoaderOptions } from '@loaders.gl/loader-utils';
import { Mesh } from '@loaders.gl/schema';
export type OBJLoaderOptions = LoaderOptions & {
obj?: {};
obj?: {
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
workerUrl?: string;
};
};

@@ -9,3 +12,19 @@ /**

*/
export declare const OBJLoader: Loader<Mesh, never, OBJLoaderOptions>;
export declare const OBJLoader: {
readonly dataType: Mesh;
readonly batchType: never;
readonly name: "OBJ";
readonly id: "obj";
readonly module: "obj";
readonly version: any;
readonly worker: true;
readonly extensions: ["obj"];
readonly mimeTypes: ["text/plain"];
readonly testText: typeof testOBJFile;
readonly options: {
readonly obj: {};
};
};
declare function testOBJFile(text: string): boolean;
export {};
//# sourceMappingURL=obj-loader.d.ts.map
// __VERSION__ is injected by babel-plugin-version-inline
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
const VERSION = typeof "4.2.0-alpha.6" !== 'undefined' ? "4.2.0-alpha.6" : 'latest';
/**

@@ -8,2 +8,4 @@ * Worker loader for the OBJ geometry format

export const OBJLoader = {
dataType: null,
batchType: null,
name: 'OBJ',

@@ -10,0 +12,0 @@ id: 'obj',

@@ -744,4 +744,6 @@ "use strict";

// src/obj-loader.ts
var VERSION = true ? "4.2.0-alpha.5" : "latest";
var VERSION = true ? "4.2.0-alpha.6" : "latest";
var OBJLoader = {
dataType: null,
batchType: null,
name: "OBJ",

@@ -833,4 +835,6 @@ id: "obj",

// src/mtl-loader.ts
var VERSION2 = true ? "4.2.0-alpha.5" : "latest";
var VERSION2 = true ? "4.2.0-alpha.6" : "latest";
var MTLLoader = {
dataType: null,
batchType: null,
name: "MTL",

@@ -837,0 +841,0 @@ id: "mtl",

{
"name": "@loaders.gl/obj",
"version": "4.2.0-alpha.6",
"version": "4.2.0-beta.1",
"description": "Framework-independent loader for the OBJ format",

@@ -45,4 +45,4 @@ "license": "MIT",

"dependencies": {
"@loaders.gl/loader-utils": "4.2.0-alpha.6",
"@loaders.gl/schema": "4.2.0-alpha.6"
"@loaders.gl/loader-utils": "4.2.0-beta.1",
"@loaders.gl/schema": "4.2.0-beta.1"
},

@@ -52,3 +52,3 @@ "peerDependencies": {

},
"gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca"
"gitHead": "c386a9196516fe3ff24847b40e6c77be039cf905"
}

@@ -0,1 +1,5 @@

// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright vis.gl contributors
import type {LoaderWithParser} from '@loaders.gl/loader-utils';

@@ -14,2 +18,4 @@ import type {Mesh} from '@loaders.gl/schema';

export type {OBJLoaderOptions} from './obj-loader';
export {OBJWorkerLoader};

@@ -20,3 +26,3 @@

*/
export const OBJLoader: LoaderWithParser<Mesh, never, OBJLoaderOptions> = {
export const OBJLoader = {
...OBJWorkerLoader,

@@ -26,3 +32,3 @@ parse: async (arrayBuffer: ArrayBuffer, options?: OBJLoaderOptions) =>

parseTextSync: (text: string, options?: OBJLoaderOptions) => parseOBJ(text, options)
};
} as const satisfies LoaderWithParser<Mesh, never, OBJLoaderOptions>;

@@ -34,3 +40,3 @@ // MTLLoader

*/
export const MTLLoader: LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions> = {
export const MTLLoader = {
...MTLWorkerLoader,

@@ -40,2 +46,2 @@ parse: async (arrayBuffer: ArrayBuffer, options?: MTLLoaderOptions) =>

parseTextSync: (text: string, options?: MTLLoaderOptions) => parseMTL(text, options?.mtl)
};
} as const satisfies LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions>;

@@ -19,3 +19,6 @@ // loaders.gl

*/
export const MTLLoader: Loader<MTLMaterial[], never, LoaderOptions> = {
export const MTLLoader = {
dataType: null as unknown as MTLMaterial[],
batchType: null as never,
name: 'MTL',

@@ -32,2 +35,2 @@ id: 'mtl',

}
};
} as const satisfies Loader<MTLMaterial[], never, LoaderOptions>;

@@ -9,3 +9,6 @@ import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';

export type OBJLoaderOptions = LoaderOptions & {
obj?: {};
obj?: {
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
workerUrl?: string;
};
};

@@ -16,3 +19,6 @@

*/
export const OBJLoader: Loader<Mesh, never, OBJLoaderOptions> = {
export const OBJLoader = {
dataType: null as unknown as Mesh,
batchType: null as never,
name: 'OBJ',

@@ -29,3 +35,3 @@ id: 'obj',

}
};
} as const satisfies Loader<Mesh, never, OBJLoaderOptions>;

@@ -32,0 +38,0 @@ function testOBJFile(text: string): boolean {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc