PageSourceSearch

https://fineenvs-trackio-latex-ocr.hf.space/assets/plyParser-BfV0GIQf.js

js fineenvs-trackio-latex-ocr.hf.space collected 2026-10-04 16:52:11 UTC 4,688 bytes, 1 lines download raw bytes

1const C={char:[1,"getInt8"],int8:[1,"getInt8"],uchar:[1,"getUint8"],uint8:[1,"getUint8"],short:[2,"getInt16"],int16:[2,"getInt16"],ushort:[2,"getUint16"],uint16:[2,"getUint16"],int:[4,"getInt32"],int32:[4,"getInt32"],uint:[4,"getUint32"],uint32:[4,"getUint32"],float:[4,"getFloat32"],float32:[4,"getFloat32"],double:[8,"getFloat64"],float64:[8,"getFloat64"]};function V(s){const r=new TextEncoder().encode("end_header");e:for(let t=0;t<=s.length-r.length;t+=1){for(let o=0;o<r.length;o+=1)if(s[t+o]!==r[o])continue e;let n=t+r.length;return s[n]===13&&(n+=1),s[n]===10&&(n+=1),{header:t+r.length,body:n}}throw new Error("PLY header is missing end_header")}function k(s){var m,x;const r=new Uint8Array(s),t=V(r),o=new TextDecoder("ascii").decode(r.subarray(0,t.header)).split(/\r?\n/);if(((m=o[0])==null?void 0:m.trim())!=="ply")throw new Error("Invalid PLY signature");const u=(x=o.find(y=>y.startsWith("format ")))==null?void 0:x.split(/\s+/)[1];if(!["ascii","binary_little_endian","binary_big_endian"].includes(u))throw new Error(`Unsupported PLY encoding: ${u||"unknown"}`);const p=[];let d=null;for(const y of o){const i=y.trim().split(/\s+/);if(i[0]==="element"&&i.length>=3){if(d={name:i[1],count:Number(i[2]),properties:[]},!Number.isSafeInteger(d.count)||d.count<0)throw new Error(`Invalid PLY element count: ${i[2]}`);p.push(d)}else i[0]==="property"&&d&&(i[1]==="list"&&i.length>=5?d.properties.push({name:i[4],list:!0,countType:i[2],valueType:i[3]}):i.length>=3&&d.properties.push({name:i[2],type:i[1]}))}return{format:u,elements:p,bodyOffset:t.body}}function q(s,r){const t=new TextDecoder().decode(new Uint8Array(s,r)).trim(),n=t?t.split(/\s+/):[];let o=0;return()=>{const u=Number(n[o]);if(o+=1,!Number.isFinite(u))throw new Error("Invalid numeric value in ASCII PLY");return u}}function H(s,r,t){const n=new DataView(s);let o=r;return u=>{const p=C[u];if(!p)throw new Error(`Unsupported PLY property type: ${u}`);if(o+p[0]>n.byteLength)throw new Error("Unexpected end of binary PLY");const d=n[p[1]](o,t);return o+=p[0],d}}function w(s,...r){for(const t of r)if(s[t]!==void 0)return s[t]}function W(s,{maxPointCount:r=1/0}={}){if(r!==1/0&&(!Number.isSafeInteger(r)||r<1))throw new Error(`Invalid PLY point limit: ${r}`);const t=k(s),n=t.elements.find(e=>e.name==="vertex"),o=(n==null?void 0:n.properties)??[],u=new Set(o.map(e=>e.name)),d=!t.elements.some(e=>e.name==="face"&&e.count>0)&&n&&n.count>r,m=d?r:(n==null?void 0:n.count)??0,x=m>1?(n.count-1)/(m-1):0;let y=0;const i=e=>d?y>=m||e!==Math.floor(y*x)?!1:(y+=1,!0):!0,R=["nx","ny","nz"].every(e=>u.has(e)),M=["u","s","texture_u"].some(e=>u.has(e))&&["v","t","texture_v"].some(e=>u.has(e)),$=new Set(["red","green","blue","r","g","b"]),P=o.filter(e=>$.has(e.name)),E=P.length>0&&P.every(e=>["uchar","uint8"].includes(e.type)),N=t.format==="ascii"?q(s,t.bodyOffset):H(s,t.bodyOffset,t.format==="binary_little_endian"),I=[],_=[],L=[],U=[],v=[];let Y=!1,z=!1,S=!1,F=0;for(const e of t.elements)for(let A=0;A<e.count;A+=1){const a={};for(const l of e.properties)if(l.list){const f=N(l.countType);if(!Number.isSafeInteger(f)||f<0)throw new Error(`Invalid PLY list length: ${f}`);const b=new Array(f);for(let c=0;c<f;c+=1)b[c]=N(l.valueType);a[l.name]=b}else a[l.name]=N(l.type);if(e.name==="vertex"){const l=a.x,f=a.y,b=a.z;if(![l,f,b].every(Number.isFinite))throw new Error("PLY vertices require finite x, y, and z values");if(!i(A))continue;if(I.push(l,f,b),R){const c=a.nx,h=a.ny,g=a.nz;[c,h,g].every(Number.isFinite)?(_.push(c,h,g),Y=!0):_.push(0,0,0)}if(M){const c=w(a,"u","s","texture_u"),h=w(a,"v","t","texture_v");[c,h].every(Number.isFinite)?(L.push(c,h),z=!0):L.push(0,0)}if(P.length>0){const c=w(a,"red","r"),h=w(a,"green","g"),g=w(a,"blue","b");if([c,h,g].every(Number.isFinite)){const T=w(a,"alpha","a")??(E?255:Math.max(c,h,g)<=1?1:255);U.push(c,h,g,T),F=Math.max(F,c,h,g,T),S=!0}else U.push(148,163,184,255)}}else if(e.name==="face"){const l=a.vertex_indices??a.vertex_index;if(Array.isArray(l))for(let f=1;f<l.length-1;f+=1)v.push(l[0],l[f],l[f+1])}}if(!I.length)throw new Error("PLY contains no vertices");const O=I.length/3;for(const e of v)if(!Number.isSafeInteger(e)||e<0||e>
1=O)throw new Error(`PLY face references invalid vertex index: ${e}`);const D=!E&&F<=1?255:1;return{topology:v.length?"triangle-list":"point-list",originalVertexCount:(n==null?void 0:n.count)??O,attributes:{POSITION:{value:new Float32Array(I),size:3},...Y?{NORMAL:{value:new Float32Array(_),size:3}}:{},...z?{TEXCOORD_0:{value:new Float32Array(L),size:2}}:{},...S?{COLOR_0:{value:new Uint8Array(U.map(e=>Math.round(e*D))),size:4,normalized:!0}}:{}},indices:v.length?{value:new Uint32Array(v),size:1}:null}}export{W as parsePly};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.