vorg / geom-builder Goto Github PK
View Code? Open in Web Editor NEWSimplicial-complex-like geometry builder backed by typed arrays
License: MIT License
Simplicial-complex-like geometry builder backed by typed arrays
License: MIT License
all your options have dual type which seems confusing - why not just pass 0?
It is possible to build mesh with more than 64k vertices that creates clamped indices due to Uint16Array array for cell. Either we should switch to Uint32Array or upgrade to it once positionsIndex is above 60k
Currently we come with assumptions about supported attributes e.g. that positions are always enabled
const builder = createGeomBuilder({ colors: 4, cells: 3 })
builder.addPosition([0, 0, 0])
builder.addColor([0, 0, 0, 1])
builder.count //1
builder.positions //Float32Array [0, 0, 0]
a more generic API could be as follows:
const builder = createGeomBuilder({ positions: 3, colors: 4, cells: { stride: 3, type: Uint32Array }})
builder.add('positions', [0.0, 0.0, 0.0])
builder.add('colors', [0.0, 0.0, 0.0, 1.0])
builder.add('cells', [0, 1, 2])
buidler.positions //Float32Array [0, 0, 0]
The builder.add('positions', [])
fees weird, it should be builder.add('position', [])
but then how do we guess the name? By adding s
automatically?
Also
builder.positions
//vs
builder.get('position')
Also if we change API so much this should be new module e.g. auto-expanding-buffer
. What makes it geometry specific is assumption that all attributes grow at the same rate which is actually not always true (e.g. instancing). Would the api be then builder.count('position')
and or builder.count('cells')
?
auto-buffer
auto expanding buffer. Is there something similar on npm already?
That also leads to builder.resetAll()
and more granular builder.reset('position')
... which leads to fact that maybe we need builder per buffer?
const autoBuffer = require('auto-buffer') //free npm name!
const positions = autoBuffer() //no predefined stride/size, probably starts with length 32
positions.add([0, 0, 0])
positions.count //undefined
positions.length //3, actual used length since last reset, not allocated buffer size
let count = positions.length / 3 //diy
positions.reset()
Geom builder allows to do addPosition([x, y, z])
and addPosition(x, y, z)
to avoid vector allocation. To enable this I use arguments
parameter. Turns out it allocates a lot of junk in Firefox causing GC hiccups and has impact on CPU in Safari and Chrome as well.
//1 old
GeomBuilder.prototype.addPosition = function (pos) {
var values = arguments[0].length ? pos : arguments
//2 new, best
GeomBuilder.prototype.addPosition = function (pos) {
var values = pos
// 3 better than 1, but still slower than 2
GeomBuilder.prototype.addPosition = function (...pos) {
var values = pos[0].length ? pos[0] : pos
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.