three-stdlib 2.21.7 → 2.21.8
Sign up to get free protection for your applications and to get access to all the features.
- package/BufferGeometryUtils-903f7ecb.js +1 -0
- package/{BufferGeometryUtils-1a7a235c.js → BufferGeometryUtils-f2288d1c.js} +87 -2
- package/geometries/TextGeometry.cjs.js +1 -1
- package/geometries/TextGeometry.js +16 -10
- package/index.cjs.js +1 -1
- package/index.js +1 -1
- package/modifiers/EdgeSplitModifier.cjs.js +1 -1
- package/modifiers/SimplifyModifier.cjs.js +1 -1
- package/package.json +1 -1
- package/utils/BufferGeometryUtils.cjs.js +1 -1
- package/utils/BufferGeometryUtils.d.ts +1 -0
- package/utils/BufferGeometryUtils.js +85 -1
- package/utils/LDrawUtils.cjs.js +1 -1
- package/utils/LDrawUtils.js +1 -1
- package/BufferGeometryUtils-971dfde3.js +0 -1
package/index.js
CHANGED
@@ -58,7 +58,7 @@ export { GeometryUtils } from './utils/GeometryUtils.js';
|
|
58
58
|
export { RoughnessMipmapper } from './utils/RoughnessMipmapper.js';
|
59
59
|
export { SkeletonUtils } from './utils/SkeletonUtils.js';
|
60
60
|
export { ShadowMapViewer } from './utils/ShadowMapViewer.js';
|
61
|
-
export { computeMorphedAttributes, estimateBytesUsed, interleaveAttributes, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, toTrianglesDrawMode } from './utils/BufferGeometryUtils.js';
|
61
|
+
export { computeMorphedAttributes, estimateBytesUsed, interleaveAttributes, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, toCreasedNormals, toTrianglesDrawMode } from './utils/BufferGeometryUtils.js';
|
62
62
|
export { GeometryCompressionUtils, PackedPhongMaterial } from './utils/GeometryCompressionUtils.js';
|
63
63
|
export { CinematicCamera } from './cameras/CinematicCamera.js';
|
64
64
|
export { ConvexHull } from './math/ConvexHull.js';
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("three"),s=require("../BufferGeometryUtils-
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("three"),s=require("../BufferGeometryUtils-903f7ecb.js");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}require("../types/helpers.cjs.js");var o=i(t);exports.EdgeSplitModifier=class{constructor(){o.default(this,"A",new e.Vector3),o.default(this,"B",new e.Vector3),o.default(this,"C",new e.Vector3),o.default(this,"positions",[]),o.default(this,"normals",new Float32Array),o.default(this,"indexes",[]),o.default(this,"pointToIndexMap",[]),o.default(this,"splitIndexes",[]),o.default(this,"oldNormals",[]),o.default(this,"computeNormals",(()=>{this.normals=new Float32Array(3*this.indexes.length);for(let t=0;t<this.indexes.length;t+=3){let e=this.indexes[t];this.A.set(this.positions[3*e],this.positions[3*e+1],this.positions[3*e+2]),e=this.indexes[t+1],this.B.set(this.positions[3*e],this.positions[3*e+1],this.positions[3*e+2]),e=this.indexes[t+2],this.C.set(this.positions[3*e],this.positions[3*e+1],this.positions[3*e+2]),this.C.sub(this.B),this.A.sub(this.B);const s=this.C.cross(this.A).normalize();for(let e=0;e<3;e++)this.normals[3*(t+e)]=s.x,this.normals[3*(t+e)+1]=s.y,this.normals[3*(t+e)+2]=s.z}})),o.default(this,"mapPositionsToIndexes",(()=>{this.pointToIndexMap=Array(this.positions.length/3);for(let t=0;t<this.indexes.length;t++){const e=this.indexes[t];null==this.pointToIndexMap[e]&&(this.pointToIndexMap[e]=[]),this.pointToIndexMap[e].push(t)}})),o.default(this,"edgeSplitToGroups",((t,e,s)=>{this.A.set(this.normals[3*s],this.normals[3*s+1],this.normals[3*s+2]).normalize();const i={splitGroup:[],currentGroup:[s]};for(let o of t)o!==s&&(this.B.set(this.normals[3*o],this.normals[3*o+1],this.normals[3*o+2]).normalize(),this.B.dot(this.A)<e?i.splitGroup.push(o):i.currentGroup.push(o));return i})),o.default(this,"edgeSplit",((t,e,s=null)=>{if(0===t.length)return;const i=[];for(let s of t)i.push(this.edgeSplitToGroups(t,e,s));let o=i[0];for(let t of i)t.currentGroup.length>o.currentGroup.length&&(o=t);null!=s&&this.splitIndexes.push({original:s,indexes:o.currentGroup}),o.splitGroup.length&&this.edgeSplit(o.splitGroup,e,s||o.currentGroup[0])})),o.default(this,"modify",((t,i,o=!0)=>{let r=!1;if(t.attributes.normal&&(r=!0,t=t.clone(),!0===o&&null!==t.index&&(this.oldNormals=t.attributes.normal.array),t.deleteAttribute("normal")),null==t.index){if(void 0===s.BufferGeometryUtils)throw"THREE.EdgeSplitModifier relies on BufferGeometryUtils";t=s.mergeVertices(t)}this.indexes=t.index.array,this.positions=t.getAttribute("position").array,this.computeNormals(),this.mapPositionsToIndexes(),this.splitIndexes=[];for(let t of this.pointToIndexMap)this.edgeSplit(t,Math.cos(i)-.001);const n={};for(let s of Object.keys(t.attributes)){const i=t.attributes[s],o=new i.array.constructor((this.indexes.length+this.splitIndexes.length)*i.itemSize);o.set(i.array),n[s]=new e.BufferAttribute(o,i.itemSize,i.normalized)}const l=new Uint32Array(this.indexes.length);l.set(this.indexes);for(let t=0;t<this.splitIndexes.length;t++){const e=this.splitIndexes[t],s=this.indexes[e.original];for(let e of Object.values(n))for(let i=0;i<e.itemSize;i++)e.array[(this.indexes.length+t)*e.itemSize+i]=e.array[s*e.itemSize+i];for(let s of e.indexes)l[s]=this.indexes.length+t}(t=new e.BufferGeometry).setIndex(new e.BufferAttribute(l,1));for(let e of Object.keys(n))t.setAttribute(e,n[e]);if(r&&(t.computeVertexNormals(),null!==this.oldNormals)){const e=new Array(this.oldNormals.length/3).fill(!1);for(let t of this.splitIndexes)e[t.original]=!0;for(let s=0;s<e.length;s++)if(!1===e[s])for(let e=0;e<3;e++)t.attributes.normal.array[3*s+e]=this.oldNormals[3*s+e]}return t}))}};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three"),o=require("../BufferGeometryUtils-
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three"),o=require("../BufferGeometryUtils-903f7ecb.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("../types/helpers.cjs.js");var i=s(e);const r=new t.Vector3,h=new t.Vector3;function n(e,t){const o=e.indexOf(t);o>-1&&e.splice(o,1)}class l{constructor(e,t){i.default(this,"position",void 0),i.default(this,"id",void 0),i.default(this,"faces",void 0),i.default(this,"neighbors",void 0),i.default(this,"collapseCost",void 0),i.default(this,"collapseNeighbor",void 0),i.default(this,"minCost",0),i.default(this,"totalCost",0),i.default(this,"costCount",0),this.position=e,this.id=t,this.faces=[],this.neighbors=[],this.collapseCost=0,this.collapseNeighbor=null}addUniqueNeighbor(e){var t,o;t=this.neighbors,o=e,-1===t.indexOf(o)&&t.push(o)}removeIfNonNeighbor(e){const t=this.neighbors,o=this.faces,s=t.indexOf(e);if(-1!==s){for(let t=0;t<o.length;t++)if(o[t].hasVertex(e))return;t.splice(s,1)}}}class a{constructor(e,o,s,r,h,n){i.default(this,"a",void 0),i.default(this,"b",void 0),i.default(this,"c",void 0),i.default(this,"v1",void 0),i.default(this,"v2",void 0),i.default(this,"v3",void 0),i.default(this,"normal",new t.Vector3),this.a=r,this.b=h,this.c=n,this.v1=e,this.v2=o,this.v3=s,this.computeNormal(),e.faces.push(this),e.addUniqueNeighbor(o),e.addUniqueNeighbor(s),o.faces.push(this),o.addUniqueNeighbor(e),o.addUniqueNeighbor(s),s.faces.push(this),s.addUniqueNeighbor(e),s.addUniqueNeighbor(o)}computeNormal(){const e=this.v1.position,t=this.v2.position,o=this.v3.position;r.subVectors(o,t),h.subVectors(e,t),r.cross(h).normalize(),this.normal.copy(r)}hasVertex(e){return e===this.v1||e===this.v2||e===this.v3}replaceVertex(e,t){e===this.v1?this.v1=t:e===this.v2?this.v2=t:e===this.v3&&(this.v3=t),n(e.faces,this),t.faces.push(this),e.removeIfNonNeighbor(this.v1),this.v1.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v2),this.v2.removeIfNonNeighbor(e),e.removeIfNonNeighbor(this.v3),this.v3.removeIfNonNeighbor(e),this.v1.addUniqueNeighbor(this.v2),this.v1.addUniqueNeighbor(this.v3),this.v2.addUniqueNeighbor(this.v1),this.v2.addUniqueNeighbor(this.v3),this.v3.addUniqueNeighbor(this.v1),this.v3.addUniqueNeighbor(this.v2),this.computeNormal()}}exports.SimplifyModifier=class{constructor(){i.default(this,"computeEdgeCollapseCost",((e,t)=>{const o=t.position.distanceTo(e.position);let s=0;const i=[];let r,h,n,l=e.faces.length;for(r=0;r<l;r++)h=e.faces[r],h.hasVertex(t)&&i.push(h);for(r=0;r<l;r++){let t=1;h=e.faces[r];for(let e=0;e<i.length;e++){n=i[e];const o=h.normal.dot(n.normal);t=Math.min(t,(1.001-o)/2)}s=Math.max(s,t)}i.length<2&&(s=1);return o*s+0})),i.default(this,"computeEdgeCostAtVertex",(e=>{if(0===e.neighbors.length)return e.collapseNeighbor=null,void(e.collapseCost=-.01);e.collapseCost=1e5,e.collapseNeighbor=null;for(let t=0;t<e.neighbors.length;t++){const o=this.computeEdgeCollapseCost(e,e.neighbors[t]);e.collapseNeighbor||(e.collapseNeighbor=e.neighbors[t],e.collapseCost=o,e.minCost=o,e.totalCost=0,e.costCount=0),e.costCount++,e.totalCost+=o,o<e.minCost&&(e.collapseNeighbor=e.neighbors[t],e.minCost=o)}e.collapseCost=e.totalCost/e.costCount})),i.default(this,"removeFace",((e,t)=>{n(t,e),e.v1&&n(e.v1.faces,e),e.v2&&n(e.v2.faces,e),e.v3&&n(e.v3.faces,e);const o=[e.v1,e.v2,e.v3];let s,i;for(let e=0;e<3;e++)s=o[e],i=o[(e+1)%3],s&&i&&(s.removeIfNonNeighbor(i),i.removeIfNonNeighbor(s))})),i.default(this,"collapse",((e,t,o,s)=>{if(!s)return void this.removeVertex(o,e);let i;const r=[];for(i=0;i<o.neighbors.length;i++)r.push(o.neighbors[i]);for(i=o.faces.length-1;i>=0;i--)o.faces[i].hasVertex(s)&&this.removeFace(o.faces[i],t);for(i=o.faces.length-1;i>=0;i--)o.faces[i].replaceVertex(o,s);for(this.removeVertex(o,e),i=0;i<r.length;i++)this.computeEdgeCostAtVertex(r[i])})),i.default(this,"minimumCostEdge",(e=>{let t=e[0];for(let o=0;o<e.length;o++)e[o].collapseCost<t.collapseCost&&(t=e[o]);return t})),i.default(this,"modify",((e,s)=>{const i=(e=e.clone()).attributes;for(let t in i)"position"!==t&&e.deleteAttribute(t);const r=[],h=[],n=(e=o.mergeVertices(e)).getAttribute("position");for(let e=0;e<n.count;e++){const o=(new t.Vector3).fromBufferAttribute(n,e),s=new l(o,e);r.push(s)}const c=e.getIndex();if(null!==c)for(let e=0;e<c.count;e+=3){const t=c.getX(e),o=c.getX(e+1),s=c.getX(e+2),i=new a(r[t],r[o],r[s],t,o,s);h.push(i)}else for(let e=0;e<n.count;e+=3){const t=e,o=e+1,s=e+2,i=new a(r[t],r[o],r[s],t,o,s);h.push(i)}for(let e=0,t=r.length;e<t;e++)this.computeEdgeCostAtVertex(r[e]);let f,u=s;for(;u--;){if(f=this.minimumCostEdge(r),!f){console.log("THREE.SimplifyModifier: No next vertex");break}this.collapse(r,h,f,f.collapseNeighbor)}const d=new t.BufferGeometry,v=[];let g=[];for(let e=0;e<r.length;e++){const t=r[e].position;v.push(t.x,t.y,t.z)}for(let e=0;e<h.length;e++){const t=h[e],o=r.indexOf(t.v1),s=r.indexOf(t.v2),i=r.indexOf(t.v3);g.push(o,s,i)}return d.setAttribute("position",new t.Float32BufferAttribute(v,3)),d.setIndex(g),d}))}removeVertex(e,t){for(console.assert(0===e.faces.length);e.neighbors.length;){n(e.neighbors.pop().neighbors,e)}n(t,e)}};
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("three"),require("../types/helpers.cjs.js");var e=require("../BufferGeometryUtils-
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("three"),require("../types/helpers.cjs.js");var e=require("../BufferGeometryUtils-903f7ecb.js");exports.computeMorphedAttributes=e.computeMorphedAttributes,exports.estimateBytesUsed=e.estimateBytesUsed,exports.interleaveAttributes=e.interleaveAttributes,exports.mergeBufferAttributes=e.mergeBufferAttributes,exports.mergeBufferGeometries=e.mergeBufferGeometries,exports.mergeVertices=e.mergeVertices,exports.toCreasedNormals=e.toCreasedNormals,exports.toTrianglesDrawMode=e.toTrianglesDrawMode;
|
@@ -12,3 +12,4 @@ export declare type ComputedMorphedAttribute = {
|
|
12
12
|
morphedNormalAttribute: Float32BufferAttribute;
|
13
13
|
};
|
14
14
|
export declare function computeMorphedAttributes(object: Mesh | Line | Points): ComputedMorphedAttribute | null;
|
15
|
+
export declare function toCreasedNormals(geometry: BufferGeometry, creaseAngle?: number): BufferGeometry;
|
@@ -639,6 +639,90 @@ function computeMorphedAttributes(object) {
|
|
639
639
|
morphedPositionAttribute: morphedPositionAttribute,
|
640
640
|
morphedNormalAttribute: morphedNormalAttribute
|
641
641
|
};
|
642
|
+
} // Creates a new, non-indexed geometry with smooth normals everywhere except faces that meet at
|
643
|
+
// an angle greater than the crease angle.
|
644
|
+
|
645
|
+
function toCreasedNormals(geometry, creaseAngle = Math.PI / 3
|
646
|
+
/* 60 degrees */
|
647
|
+
) {
|
648
|
+
const creaseDot = Math.cos(creaseAngle);
|
649
|
+
const hashMultiplier = (1 + 1e-10) * 1e2; // reusable vertors
|
650
|
+
|
651
|
+
const verts = [new Vector3(), new Vector3(), new Vector3()];
|
652
|
+
const tempVec1 = new Vector3();
|
653
|
+
const tempVec2 = new Vector3();
|
654
|
+
const tempNorm = new Vector3();
|
655
|
+
const tempNorm2 = new Vector3(); // hashes a vector
|
656
|
+
|
657
|
+
function hashVertex(v) {
|
658
|
+
const x = ~~(v.x * hashMultiplier);
|
659
|
+
const y = ~~(v.y * hashMultiplier);
|
660
|
+
const z = ~~(v.z * hashMultiplier);
|
661
|
+
return `${x},${y},${z}`;
|
662
|
+
}
|
663
|
+
|
664
|
+
const resultGeometry = geometry.toNonIndexed();
|
665
|
+
const posAttr = resultGeometry.attributes.position;
|
666
|
+
const vertexMap = {}; // find all the normals shared by commonly located vertices
|
667
|
+
|
668
|
+
for (let i = 0, l = posAttr.count / 3; i < l; i++) {
|
669
|
+
const i3 = 3 * i;
|
670
|
+
const a = verts[0].fromBufferAttribute(posAttr, i3 + 0);
|
671
|
+
const b = verts[1].fromBufferAttribute(posAttr, i3 + 1);
|
672
|
+
const c = verts[2].fromBufferAttribute(posAttr, i3 + 2);
|
673
|
+
tempVec1.subVectors(c, b);
|
674
|
+
tempVec2.subVectors(a, b); // add the normal to the map for all vertices
|
675
|
+
|
676
|
+
const normal = new Vector3().crossVectors(tempVec1, tempVec2).normalize();
|
677
|
+
|
678
|
+
for (let n = 0; n < 3; n++) {
|
679
|
+
const vert = verts[n];
|
680
|
+
const hash = hashVertex(vert);
|
681
|
+
|
682
|
+
if (!(hash in vertexMap)) {
|
683
|
+
vertexMap[hash] = [];
|
684
|
+
}
|
685
|
+
|
686
|
+
vertexMap[hash].push(normal);
|
687
|
+
}
|
688
|
+
} // average normals from all vertices that share a common location if they are within the
|
689
|
+
// provided crease threshold
|
690
|
+
|
691
|
+
|
692
|
+
const normalArray = new Float32Array(posAttr.count * 3);
|
693
|
+
const normAttr = new BufferAttribute(normalArray, 3, false);
|
694
|
+
|
695
|
+
for (let i = 0, l = posAttr.count / 3; i < l; i++) {
|
696
|
+
// get the face normal for this vertex
|
697
|
+
const i3 = 3 * i;
|
698
|
+
const a = verts[0].fromBufferAttribute(posAttr, i3 + 0);
|
699
|
+
const b = verts[1].fromBufferAttribute(posAttr, i3 + 1);
|
700
|
+
const c = verts[2].fromBufferAttribute(posAttr, i3 + 2);
|
701
|
+
tempVec1.subVectors(c, b);
|
702
|
+
tempVec2.subVectors(a, b);
|
703
|
+
tempNorm.crossVectors(tempVec1, tempVec2).normalize(); // average all normals that meet the threshold and set the normal value
|
704
|
+
|
705
|
+
for (let n = 0; n < 3; n++) {
|
706
|
+
const vert = verts[n];
|
707
|
+
const hash = hashVertex(vert);
|
708
|
+
const otherNormals = vertexMap[hash];
|
709
|
+
tempNorm2.set(0, 0, 0);
|
710
|
+
|
711
|
+
for (let k = 0, lk = otherNormals.length; k < lk; k++) {
|
712
|
+
const otherNorm = otherNormals[k];
|
713
|
+
|
714
|
+
if (tempNorm.dot(otherNorm) > creaseDot) {
|
715
|
+
tempNorm2.add(otherNorm);
|
716
|
+
}
|
717
|
+
}
|
718
|
+
|
719
|
+
tempNorm2.normalize();
|
720
|
+
normAttr.setXYZ(i3 + n, tempNorm2.x, tempNorm2.y, tempNorm2.z);
|
721
|
+
}
|
722
|
+
}
|
723
|
+
|
724
|
+
resultGeometry.setAttribute('normal', normAttr);
|
725
|
+
return resultGeometry;
|
642
726
|
}
|
643
727
|
|
644
|
-
export { computeMorphedAttributes, estimateBytesUsed, interleaveAttributes, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, toTrianglesDrawMode };
|
728
|
+
export { computeMorphedAttributes, estimateBytesUsed, interleaveAttributes, mergeBufferAttributes, mergeBufferGeometries, mergeVertices, toCreasedNormals, toTrianglesDrawMode };
|
package/utils/LDrawUtils.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),r=require("../BufferGeometryUtils-
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),r=require("../BufferGeometryUtils-903f7ecb.js");require("../types/helpers.cjs.js");exports.LDrawUtils=class{static mergeObject(e){function i(r,e,i,n){const a=new t.BufferGeometry,o=r.getAttribute("position").array,s=3===i?r.getAttribute("normal").array:null,u=Math.min(e.count,Math.floor(o.length/3)-e.start),l=3*e.start,c=3*(e.start+u),f=o.subarray(l,c),m=null!==s?s.subarray(l,c):null;if(a.setAttribute("position",new t.BufferAttribute(f,3)),null!==m&&a.setAttribute("normal",new t.BufferAttribute(m,3)),n){const e=r.getAttribute("control0").array.subarray(l,c),i=r.getAttribute("control1").array.subarray(l,c),n=r.getAttribute("direction").array.subarray(l,c);a.setAttribute("control0",new t.BufferAttribute(e,3,!1)),a.setAttribute("control1",new t.BufferAttribute(i,3,!1)),a.setAttribute("direction",new t.BufferAttribute(n,3,!1))}return a}function n(t,r,e){const i=e[t.uuid];i?i.arr.push(r):e[t.uuid]={mat:t,arr:[r]}}function a(t,r){if(!t)return;const e=t.array,i=Math.floor(e.length/3);let n=0;for(let t=0;t<i;t++){const t=e[n],i=e[n+1],a=e[n+2];e[n]=e[n+3],e[n+1]=e[n+4],e[n+2]=e[n+5],e[n+3]=t,e[n+4]=i,e[n+5]=a,n+=3*r}}const o={},s={},u={};e.updateMatrixWorld(!0);const l=new t.Matrix3;e.traverse((t=>{if(t.isMesh|t.isLineSegments){const r=t.isMesh?3:2,e=t.geometry.clone();t.matrixWorld.determinant()<0&&(a(e.attributes.position,r),a(e.attributes.normal,r)),e.applyMatrix4(t.matrixWorld),t.isConditionalLine&&(e.attributes.control0.applyMatrix4(t.matrixWorld),e.attributes.control1.applyMatrix4(t.matrixWorld),l.getNormalMatrix(t.matrixWorld),e.attributes.direction.applyNormalMatrix(l));const c=t.isMesh?o:t.isConditionalLine?u:s;if(Array.isArray(t.material))for(const a in e.groups){const o=e.groups[a];n(t.material[o.materialIndex],i(e,o,r,t.isConditionalLine),c)}else n(t.material,e,c)}}));const c=new t.Group,f=Object.keys(o);for(const e in f){const i=o[f[e]],n=r.mergeBufferGeometries(i.arr);c.add(new t.Mesh(n,i.mat))}const m=Object.keys(s);for(const e in m){const i=s[m[e]],n=r.mergeBufferGeometries(i.arr);c.add(new t.LineSegments(n,i.mat))}const b=Object.keys(u);for(const e in b){const i=u[b[e]],n=r.mergeBufferGeometries(i.arr),a=new t.LineSegments(n,i.mat);a.isConditionalLine=!0,c.add(a)}return c.userData.constructionStep=0,c.userData.numConstructionSteps=1,c}};
|
package/utils/LDrawUtils.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Matrix3, Group, Mesh, LineSegments, BufferGeometry, BufferAttribute } from 'three';
|
2
|
-
import { m as mergeBufferGeometries } from '../BufferGeometryUtils-
|
2
|
+
import { m as mergeBufferGeometries } from '../BufferGeometryUtils-f2288d1c.js';
|
3
3
|
import '../types/helpers.js';
|
4
4
|
|
5
5
|
class LDrawUtils {
|
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";var e=require("three"),t=require("./types/helpers.cjs.js");const r=(t,r)=>{const i=null!==t[0].index,s=new Set(Object.keys(t[0].attributes)),n=new Set(Object.keys(t[0].morphAttributes)),u={},a={},l=t[0].morphTargetsRelative,f=new e.BufferGeometry;let m=0;if(t.forEach(((e,t)=>{let o=0;if(i!==(null!==e.index))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(let r in e.attributes){if(!s.has(r))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+'. All geometries must have compatible attributes; make sure "'+r+'" attribute exists among all geometries, or in none of them.'),null;void 0===u[r]&&(u[r]=[]),u[r].push(e.attributes[r]),o++}if(o!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+". Make sure all geometries have the same number of attributes."),null;if(l!==e.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(let r in e.morphAttributes){if(!n.has(r))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+". .morphAttributes must be consistent throughout all geometries."),null;void 0===a[r]&&(a[r]=[]),a[r].push(e.morphAttributes[r])}if(f.userData.mergedUserData=f.userData.mergedUserData||[],f.userData.mergedUserData.push(e.userData),r){let r;if(e.index)r=e.index.count;else{if(void 0===e.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+t+". The geometry must have either an index or a position attribute"),null;r=e.attributes.position.count}f.addGroup(m,r,t),m+=r}})),i){let e=0;const r=[];t.forEach((t=>{const o=t.index;for(let t=0;t<o.count;++t)r.push(o.getX(t)+e);e+=t.attributes.position.count})),f.setIndex(r)}for(let e in u){const t=o(u[e]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+e+" attribute."),null;f.setAttribute(e,t)}for(let e in a){const t=a[e][0].length;if(0===t)break;f.morphAttributes=f.morphAttributes||{},f.morphAttributes[e]=[];for(let r=0;r<t;++r){const t=[];for(let o=0;o<a[e].length;++o)t.push(a[e][o][r]);const i=o(t);if(!i)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+e+" morphAttribute."),null;f.morphAttributes[e].push(i)}}return f},o=t=>{let r,o,i,s=0;if(t.forEach((e=>(void 0===r&&(r=e.array.constructor),r!==e.array.constructor?(console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null):(void 0===o&&(o=e.itemSize),o!==e.itemSize?(console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null):(void 0===i&&(i=e.normalized),i!==e.normalized?(console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null):void(s+=e.array.length)))))),r&&o){const n=new r(s);let u=0;return t.forEach((e=>{n.set(e.array,u),u+=e.array.length})),new e.BufferAttribute(n,o,i)}},i=r=>{let o,i=0,s=0;for(let e=0,t=r.length;e<t;++e){const t=r[e];if(void 0===o&&(o=t.array.constructor),o!==t.array.constructor)return console.error("AttributeBuffers of different types cannot be interleaved"),null;i+=t.array.length,s+=t.itemSize}const n=new e.InterleavedBuffer(new o(i),s);let u=0;const a=[],l=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let o=0,i=r.length;o<i;o++){const i=r[o],s=i.itemSize,m=i.count,c=new e.InterleavedBufferAttribute(n,s,u,i.normalized);a.push(c),u+=s;for(let e=0;e<m;e++)for(let r=0;r<s;r++){t.getWithKey(c,f[r])(e,t.getWithKey(i,l[r])(e))}}return a};function s(e){let t=0;for(let r in e.attributes){const o=e.getAttribute(r);t+=o.count*o.itemSize*o.array.BYTES_PER_ELEMENT}const r=e.getIndex();return t+=r?r.count*r.itemSize*r.array.BYTES_PER_ELEMENT:0,t}function n(t,r=1e-4){r=Math.max(r,Number.EPSILON);const o={},i=t.getIndex(),s=t.getAttribute("position"),n=i?i.count:s.count;let u=0;const a=Object.keys(t.attributes),l={},f={},m=[],c=["getX","getY","getZ","getW"];for(let e=0,r=a.length;e<r;e++){const r=a[e];l[r]=[];const o=t.morphAttributes[r];o&&(f[r]=new Array(o.length).fill(0).map((()=>[])))}const g=Math.log10(1/r),h=Math.pow(10,g);for(let e=0;e<n;e++){const r=i?i.getX(e):e;let s="";for(let e=0,o=a.length;e<o;e++){const o=a[e],i=t.getAttribute(o),n=i.itemSize;for(let e=0;e<n;e++)s+=~~(i[c[e]](r)*h)+","}if(s in o)m.push(o[s]);else{for(let e=0,o=a.length;e<o;e++){const o=a[e],i=t.getAttribute(o),s=t.morphAttributes[o],n=i.itemSize,u=l[o],m=f[o];for(let e=0;e<n;e++){const t=c[e];if(u.push(i[t](r)),s)for(let e=0,o=s.length;e<o;e++)m[e].push(s[e][t](r))}}o[s]=u,m.push(u),u++}}const d=t.clone();for(let r=0,o=a.length;r<o;r++){const o=a[r],i=t.getAttribute(o),s=new i.array.constructor(l[o]),n=new e.BufferAttribute(s,i.itemSize,i.normalized);if(d.setAttribute(o,n),o in f)for(let r=0;r<f[o].length;r++){const i=t.morphAttributes[o][r],s=new i.array.constructor(f[o][r]),n=new e.BufferAttribute(s,i.itemSize,i.normalized);d.morphAttributes[o][r]=n}}return d.setIndex(m),d}function u(t,r){if(r===e.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),t;if(r===e.TriangleFanDrawMode||r===e.TriangleStripDrawMode){let o=t.getIndex();if(null===o){const e=[],r=t.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<r.count;t++)e.push(t);t.setIndex(e),o=t.getIndex()}const i=o.count-2,s=[];if(o)if(r===e.TriangleFanDrawMode)for(let e=1;e<=i;e++)s.push(o.getX(0)),s.push(o.getX(e)),s.push(o.getX(e+1));else for(let e=0;e<i;e++)e%2==0?(s.push(o.getX(e)),s.push(o.getX(e+1)),s.push(o.getX(e+2))):(s.push(o.getX(e+2)),s.push(o.getX(e+1)),s.push(o.getX(e)));s.length/3!==i&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const n=t.clone();return n.setIndex(s),n.clearGroups(),n}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",r),t}function a(t){if(!0!==t.geometry.isBufferGeometry)return console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry."),null;const r=new e.Vector3,o=new e.Vector3,i=new e.Vector3,s=new e.Vector3,n=new e.Vector3,u=new e.Vector3,a=new e.Vector3,l=new e.Vector3,f=new e.Vector3;function m(e,t,m,c,g,h,d,b,p){r.fromBufferAttribute(m,h),o.fromBufferAttribute(m,d),i.fromBufferAttribute(m,b);const y=e.morphTargetInfluences;if(t.morphTargets&&c&&y){a.set(0,0,0),l.set(0,0,0),f.set(0,0,0);for(let e=0,t=c.length;e<t;e++){const t=y[e],m=c[e];0!==t&&(s.fromBufferAttribute(m,h),n.fromBufferAttribute(m,d),u.fromBufferAttribute(m,b),g?(a.addScaledVector(s,t),l.addScaledVector(n,t),f.addScaledVector(u,t)):(a.addScaledVector(s.sub(r),t),l.addScaledVector(n.sub(o),t),f.addScaledVector(u.sub(i),t)))}r.add(a),o.add(l),i.add(f)}e.isSkinnedMesh&&(e.boneTransform(h,r),e.boneTransform(d,o),e.boneTransform(b,i)),p[3*h+0]=r.x,p[3*h+1]=r.y,p[3*h+2]=r.z,p[3*d+0]=o.x,p[3*d+1]=o.y,p[3*d+2]=o.z,p[3*b+0]=i.x,p[3*b+1]=i.y,p[3*b+2]=i.z}const c=t.geometry,g=t.material;let h,d,b;const p=c.index,y=c.attributes.position,A=c.morphAttributes.position,B=c.morphTargetsRelative,w=c.attributes.normal,E=c.morphAttributes.position,x=c.groups,T=c.drawRange;let G,M,S,v,U,z,R,X;const D=new Float32Array(y.count*y.itemSize),V=new Float32Array(w.count*w.itemSize);if(null!==p)if(Array.isArray(g))for(G=0,S=x.length;G<S;G++)for(U=x[G],z=g[U.materialIndex],R=Math.max(U.start,T.start),X=Math.min(U.start+U.count,T.start+T.count),M=R,v=X;M<v;M+=3)h=p.getX(M),d=p.getX(M+1),b=p.getX(M+2),m(t,z,y,A,B,h,d,b,D),m(t,z,w,E,B,h,d,b,V);else for(R=Math.max(0,T.start),X=Math.min(p.count,T.start+T.count),G=R,S=X;G<S;G+=3)h=p.getX(G),d=p.getX(G+1),b=p.getX(G+2),m(t,g,y,A,B,h,d,b,D),m(t,g,w,E,B,h,d,b,V);else if(void 0!==y)if(Array.isArray(g))for(G=0,S=x.length;G<S;G++)for(U=x[G],z=g[U.materialIndex],R=Math.max(U.start,T.start),X=Math.min(U.start+U.count,T.start+T.count),M=R,v=X;M<v;M+=3)h=M,d=M+1,b=M+2,m(t,z,y,A,B,h,d,b,D),m(t,z,w,E,B,h,d,b,V);else for(R=Math.max(0,T.start),X=Math.min(y.count,T.start+T.count),G=R,S=X;G<S;G+=3)h=G,d=G+1,b=G+2,m(t,g,y,A,B,h,d,b,D),m(t,g,w,E,B,h,d,b,V);return{positionAttribute:y,normalAttribute:w,morphedPositionAttribute:new e.Float32BufferAttribute(D,3),morphedNormalAttribute:new e.Float32BufferAttribute(V,3)}}var l=Object.freeze({__proto__:null,mergeBufferGeometries:r,mergeBufferAttributes:o,interleaveAttributes:i,estimateBytesUsed:s,mergeVertices:n,toTrianglesDrawMode:u,computeMorphedAttributes:a});exports.BufferGeometryUtils=l,exports.computeMorphedAttributes=a,exports.estimateBytesUsed=s,exports.interleaveAttributes=i,exports.mergeBufferAttributes=o,exports.mergeBufferGeometries=r,exports.mergeVertices=n,exports.toTrianglesDrawMode=u;
|