Comparing version 1.0.42 to 1.0.43
{ | ||
"name": "optimesh", | ||
"version": "1.0.42", | ||
"version": "1.0.43", | ||
"description": "OptiMesh reduces meshes resolution to optimize performance, memory usage and download size", | ||
"cdn": "https://cdn.jsdelivr.net/npm/optimesh@1.0.32/build/main.js", | ||
"cdn": "https://cdn.jsdelivr.net/npm/optimesh@1.0.43/build/main.js", | ||
"main": "build/main.js", | ||
"jsnext:main": "build/main.module.js", | ||
"module": "build/main.module.js", | ||
"jsnext:main": "src/main.js", | ||
"module": "src/main.js", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"start": "npx http-server . -o -c-1", | ||
"build": "cp ./src/threeImport.globalThree.js ./src/threeImport.js rollup -c", | ||
"test": "jest src", | ||
"lint": "eslint src", | ||
"prepublish": "(git diff-index --quiet HEAD -- || (echo \"There are uncommitted changes\"; && exit;)) && node --experimental-modules publish.mjs", | ||
"prepublishOnly": "(git diff-index --quiet HEAD -- || (echo \"There are uncommitted changes\"; && exit;)) && node --experimental-modules publish.mjs", | ||
"postpublish": "git add package.json && git commit -m \"bump and publish %npm_package_version%\" && git push" | ||
@@ -22,2 +23,3 @@ }, | ||
"@babel/preset-env": "^7.11.5", | ||
"http-server": "^14.1.1", | ||
"rollup": "^1.32.1", | ||
@@ -24,0 +26,0 @@ "rollup-plugin-commonjs": "^10.1.0", |
@@ -1,4 +0,4 @@ | ||
import { meshSimplifier, createWorkers } from './MeshSimplifier'; | ||
import { openOptimizer, setBoneCosts } from './OptimPopup'; | ||
import { skinnedMeshClone } from './skinnedMeshClone'; | ||
import { meshSimplifier, createWorkers } from './MeshSimplifier.js'; | ||
import { openOptimizer, setBoneCosts } from './OptimPopup.js'; | ||
import { skinnedMeshClone } from './skinnedMeshClone.js'; | ||
@@ -46,4 +46,3 @@ function editorAction(editor) { | ||
}; | ||
export default { OptiMesh }; | ||
export { createWorkers, meshSimplifier, editorPlugin, openOptimizer, setBoneCosts }; | ||
export default OptiMesh; | ||
// export { createWorkers, meshSimplifier }; |
@@ -1,8 +0,5 @@ | ||
import { emptyOversizedContainer, emptyOversizedContainerIndex, zeroFill } from './BufferArrayManager'; | ||
import { emptyOversizedContainer, emptyOversizedContainerIndex, zeroFill } from './BufferArrayManager.js'; | ||
import * as CostWorker from './Worker/simplify.worker.js'; | ||
import { getIndexedPositions } from './Utils'; | ||
// import { Vector2, Vector3, BufferAttribute, BufferGeometry } from 'dvlp-three'; | ||
const { | ||
Vector2, Vector3, BufferAttribute, BufferGeometry | ||
} = dvlpThree; | ||
import { getIndexedPositions } from './Utils.js'; | ||
import { Vector2, Vector3, BufferAttribute, BufferGeometry } from './threeImport.js'; | ||
export class WebWorker { | ||
@@ -37,3 +34,4 @@ constructor(worker) { | ||
// if SAB is not available use only 1 worker per object to fully contain dataArrays that will be only available after using transferable objects | ||
const MAX_WORKERS_PER_OBJECT = typeof SharedArrayBuffer === 'undefined' ? 1 : navigator.hardwareConcurrency; | ||
const isSAB = typeof SharedArrayBuffer !== 'undefined' | ||
const MAX_WORKERS_PER_OBJECT = !isSAB ? 1 : navigator.hardwareConcurrency; | ||
const DISCARD_BELOW_VERTEX_COUNT = 400; | ||
@@ -98,5 +96,5 @@ | ||
} | ||
if (geometry.index) { | ||
geometry = geometry.toNonIndexed(); | ||
} | ||
// if (geometry.index) { | ||
// geometry = geometry.toNonIndexed(); | ||
// } | ||
@@ -148,28 +146,28 @@ preserveTexture = | ||
return reject(geometry); | ||
if (attempt >= 3) { | ||
console.log('Simplifying error messages', e); | ||
console.error( | ||
'Error in simplifying. Returning original.', | ||
geometry.name | ||
); | ||
return (resolveTop || resolve)(geometry); | ||
} | ||
console.log('Simplifying error messages', e); | ||
console.error( | ||
'Error in simplifying. Retrying in 500ms, attempt', | ||
attempt, | ||
geometry.name | ||
); | ||
const attemptCount = attempt + 1; | ||
setTimeout(() => { | ||
meshSimplifier( | ||
geometry, | ||
percentage, | ||
maximumCost, | ||
modelSize, | ||
(preserveTexture = true), | ||
attemptCount, | ||
resolveTop || resolve | ||
); | ||
}, 500); | ||
// if (attempt >= 3) { | ||
// console.log('Simplifying error messages', e); | ||
// console.error( | ||
// 'Error in simplifying. Returning original.', | ||
// geometry.name | ||
// ); | ||
// return (resolveTop || resolve)(geometry); | ||
// } | ||
// console.log('Simplifying error messages', e); | ||
// console.error( | ||
// 'Error in simplifying. Retrying in 500ms, attempt', | ||
// attempt, | ||
// geometry.name | ||
// ); | ||
// const attemptCount = attempt + 1; | ||
// setTimeout(() => { | ||
// meshSimplifier( | ||
// geometry, | ||
// percentage, | ||
// maximumCost, | ||
// modelSize, | ||
// (preserveTexture = true), | ||
// attemptCount, | ||
// resolveTop || resolve | ||
// ); | ||
// }, 500); | ||
}); | ||
@@ -188,3 +186,2 @@ }); | ||
) { | ||
console.time('reusing arrays') | ||
emptyOversizedContainerIndex(reusingDataArrays.facesView); | ||
@@ -209,7 +206,5 @@ emptyOversizedContainer(reusingDataArrays.specialCases); | ||
reusingDataArrays.buildIndexStatus.fill(0); | ||
reusingDataArrays.vertexNeighboursView.fill(0); | ||
reusingDataArrays.vertexFacesView.fill(0); | ||
reusingDataArrays.boneCosts.fill(0); | ||
console.timeEnd('reusing arrays') | ||
return reusingDataArrays; | ||
@@ -219,4 +214,3 @@ } | ||
previousVertexCount = verexCount; | ||
const SAB = | ||
typeof SharedArrayBuffer === 'undefined' ? ArrayBuffer : SharedArrayBuffer; | ||
const SAB = isSAB ? SharedArrayBuffer : ArrayBuffer | ||
// const positions = geo.attributes.position.array; | ||
@@ -309,5 +303,3 @@ const verticesAB = new SAB(verexCount * 3 * 4); | ||
} else if (geometry.isBufferGeometry) { | ||
const positionsCount = geometry.index | ||
? geometry.attributes.position.count | ||
: geometry.attributes.position.count; | ||
const positionsCount = geometry.attributes.position.count; | ||
const faceCount = geometry.index | ||
@@ -343,7 +335,12 @@ ? geometry.index.count / 3 | ||
if (geometry.skeleton) { | ||
Object.keys(geometry.boneCosts).forEach(boneName => { | ||
const idx = geometry.skeleton.bones.findIndex(bone => bone.name === boneName) | ||
if (!idx) return | ||
boneCosts[idx] = geometry.boneCosts[boneName] | ||
}) | ||
if (!geometry.boneCosts) { | ||
console.error('Optimesh: Bone costs are missing!') | ||
} else { | ||
Object.keys(geometry.boneCosts).forEach(boneName => { | ||
const idx = geometry.skeleton.bones.findIndex(bone => bone.name === boneName) | ||
if (!idx) return | ||
boneCosts[idx] = geometry.boneCosts[boneName] | ||
}) | ||
} | ||
} | ||
@@ -366,2 +363,7 @@ // console.log('new indexed addresses', newVertexIndexByOld); | ||
// position and index are indexed, but other attributes are not | ||
if (geometry.index) { | ||
geometry = geometry.toNonIndexed() | ||
} | ||
if (geometry.attributes.normal) { | ||
@@ -558,3 +560,3 @@ faceNormalsView.set(geometry.attributes.normal.array); | ||
let ifNoSABUseTransferable = undefined; | ||
if (typeof SharedArrayBuffer === 'undefined') { | ||
if (!isSAB) { | ||
ifNoSABUseTransferable = Object.keys(dataArrays).reduce((acc, el) => { | ||
@@ -623,2 +625,12 @@ acc.push(dataArrays[el].buffer); | ||
if (!isSAB) { | ||
if (event.data.dataArrays) { | ||
Object.keys(reusingDataArrays).forEach(el => { | ||
reusingDataArrays[el] = event.data.dataArrays[el]; | ||
}); | ||
} else { | ||
reusingDataArrays = null | ||
} | ||
} | ||
if (event.data.task === 'simplificationError') { | ||
@@ -631,3 +643,3 @@ errorMessages.push(event.data.message); | ||
) { | ||
if (typeof SharedArrayBuffer === 'undefined') { | ||
if (!isSAB) { | ||
resolve(event.data.dataArrays); | ||
@@ -648,4 +660,4 @@ } else { | ||
const uniqueVertices = []; | ||
const mapNewToOld = []; | ||
const mapOldToNew = []; | ||
let mapNewToOld = new Uint32Array(index.length); // this is broken? | ||
const mapOldToNew = []; | ||
let newIndexCount = 0; | ||
@@ -665,3 +677,5 @@ // find unique indices | ||
mapNewToOld.sort(); | ||
mapNewToOld = mapNewToOld.slice(0, uniqueVertices.length) // is length inclusive? | ||
mapNewToOld.sort(); // must be typed array for sort! | ||
for (let i = 0; i < mapNewToOld.length; i++) { | ||
@@ -826,3 +840,3 @@ mapOldToNew[mapNewToOld[i]] = i; | ||
const index = new Uint32Array(faceCount * 4); | ||
const index = new Uint32Array(faceCount * 3); | ||
@@ -829,0 +843,0 @@ let currentGroup = null; |
@@ -1,9 +0,6 @@ | ||
import { meshSimplifier, killWorkers, createWorkers } from './MeshSimplifier'; | ||
import * as dat from 'dat.gui'; | ||
import { skinnedMeshClone } from './skinnedMeshClone'; | ||
import { meshSimplifier, killWorkers, createWorkers } from './MeshSimplifier.js'; | ||
import * as dat from './lib/dat.gui.min.js' | ||
import { skinnedMeshClone } from './skinnedMeshClone.js'; | ||
import { AmbientLight, Box3, Color, Group, HemisphereLight, PerspectiveCamera, Scene, SpotLight, WebGLRenderer, Loader, OrbitControls } from './threeImport.js' | ||
// NO NEED TO IMPORT dvlpThree - it's added by rollup so it works with both THREE and dvlpThreee | ||
const { AmbientLight, Box3, Color, Group, HemisphereLight, PerspectiveCamera, Scene, SpotLight, WebGLRenderer, OrbitControls } = dvlpThree | ||
// import { OrbitControls } from 'dvlp-three/examples/jsm/controls/OrbitControls.js'; | ||
var camera, ocontrols, modelGroup, modelOptimized, modelOptimizedGroup, modelMaxSize, modelMaxWidthDepth, fileLoader, close, done; | ||
@@ -116,3 +113,3 @@ var boneCosts = {} | ||
dropdown.onChange(item => { | ||
fileLoader.loadURL(models[item]); | ||
fileLoader.load(models[item]); | ||
}); | ||
@@ -260,3 +257,3 @@ // setTimeout(() => { | ||
// fileLoader = new Loader(obj => setupNewObject(obj)); | ||
fileLoader = new Loader(obj => setupNewObject(obj)); | ||
@@ -303,8 +300,4 @@ function setupNewObject(scene, obj, controls, domElement) { | ||
if (OrbitControls) { | ||
ocontrols = new OrbitControls(camera, domElement); | ||
ocontrols.target.set(modelMaxWidthDepth / 2, (boxScale.max.y - boxScale.min.y) / 2, 0); | ||
} else { | ||
console.warn('Update this code to work with THREE 117+'); | ||
} | ||
ocontrols = new OrbitControls(camera, domElement); | ||
ocontrols.target.set(modelMaxWidthDepth / 2, (boxScale.max.y - boxScale.min.y) / 2, 0); | ||
@@ -311,0 +304,0 @@ optimizeModel(controls); |
@@ -34,6 +34,9 @@ // | ||
var SAB = typeof SharedArrayBuffer !== 'undefined' ? SharedArrayBuffer : ArrayBuffer; | ||
const faceCount = geometry.index ? geometry.index.count / 3 : geometry.attributes.position.count / 3; | ||
const largeIndexes = faceCount * 3 > 65536; | ||
const UIntConstructor = largeIndexes ? Uint32Array : Uint16Array; | ||
if(geometry.index) { | ||
const indexSAB = new SAB(geometry.index.array.length * 4); | ||
const indexArr = new Uint32Array(indexSAB); | ||
const indexSAB = new SAB(geometry.index.array.length * (largeIndexes ? 4 : 2)); | ||
const indexArr = new UIntConstructor(indexSAB); | ||
indexArr.set(geometry.index.array); | ||
@@ -51,12 +54,6 @@ const posSAB = new SAB(geometry.attributes.position.array.length * 4); | ||
const positionsAttr = []; | ||
const position = geometry.attributes.position.array; | ||
const faceCount = position.length / 3 / 3; | ||
const largeIndexes = faceCount * 3 > 65536; | ||
const indexBuffer = new SAB( | ||
faceCount * 3 * (largeIndexes ? 4 : 2) | ||
); | ||
const UIntConstructor = largeIndexes ? Uint32Array : Uint16Array; | ||
const indexArray = new UIntConstructor(indexBuffer); | ||
@@ -63,0 +60,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
2912832
22
7
10921