Last active
February 23, 2016 03:24
-
-
Save dcunited001/aaaf8649c9ea9b21a87d to your computer and use it in GitHub Desktop.
Swift(Spectra) - Transmuting geometry of meshes/submeshes to fill in attributes or add
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ModelIO // because it's pretty awesome | |
import Metal // because why wouldn't you want the most streamlined hardware, if that's the name of the game | |
var mesh = BlackBufferMagic(vertices: [ | |
1,0,0,0, | |
0,1,0,0, | |
0,0,1,0, | |
0,0,0,1]).itGivesMeAMesh() | |
var meshTransmuteList = mesh.attributes.map { (attr) in | |
if (Spectra.AttributeCategories.has?(attr.name)) { | |
// use dependency injection to fetch a morphism that generates this attribute category from a mesh | |
return Spectra.AttributeCategories.fetchAttrGenerator(attr.name, to: ["some": other, "mesh": categories]) | |
} | |
}.compact() // then i guess inspect for dependency conflicts or whatever, but yeh i'm probably not going to do that right now | |
var transmutedMesh = meshTransmuteList.reduce(mesh) { (transmografier) return apply(transmogrifier, mesh) } | |
// and then again for submeshes, if necessary | |
// var submeshTransmuteList = mesh.submeshs. // yada, yada |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spectra - Higher-Order Functions for teh win
(definitely, definitely pseudocode)
the above can be applied to take a list of vertices and map the edges/triangles/faces, though these are more likely to either already be populated, or they'll be populated on creation of the mesh. this stuff also works for these MDLVertexAttribute types
and most crucially, something similar should work for SUBMESH generation, which i believe will be fascinating in creating locally connected latices (where each vertex transmits 'info' to other nodes, resulting in COLORS, fucking colors.)
Higher Order 3D Geometry
these functions will also be useful for voronoi generation, or for Delauney/Fortune algorithm implementation. and i should be able to utilize this, along with compute shaders to implement a parallel 3D Delauney algorithm to connect a mesh built from streaming vertex data. yes. $#@!'ing yes
obviously, there are some performance constraints here. you can't do everything in real-time, while rendering, but performing a few compute shaders in real time really isn't so bad as long as they aren't interdependent.
Maths
experimenting with this kind of math stuff excites me. and i think this Spectra library will help me build this stuff real fastlike. I'm sure this stuff isn't completely original, but i'm really hoping that leveraging the functional nature of Swift along with the minimalistic nature of Metal will open up some interesting possibilities with this Spectra library I'm working on.
overall this is a pretty awesome way of combinating mesh/mesh categories to piece together (mesh) => (mesh) morphisms