Fork me on GitHub
#clojure-art
<
2015-12-20
>
meow14:12:36

@mikera: Saw your twitter reply. Gonna take a look at clisk.

meow15:12:22

@mikera: Would love to chat about this with you. Also interested in how to improve mesh performance. You've worked a lot on matrices and such. I want to really push the limits on mesh subdivision modeling and could really use your expertise.

mikera15:12:57

Sure.... a lot of performance stuff depends on representation though

mikera15:12:10

The reason that core.matrix+vectorz-clj is 10-20x faster than core.matrix+clojure vectors is by using unboxed primitives with Java arrays rather than the much more heavyweight approach of boxed numbers in persistent vectors

mikera15:12:43

Upshot is: you'll probably need to look at alternative representations if you really want max performance

meow15:12:20

Right. And I'd rather not reinvent the wheel there as I don't really have the experience or expertise to do so.

meow15:12:57

Have you looked at how the gmesh is represented in http://thi.ng?

meow15:12:41

Pretty simple use of clojure sets and vectors and a Vec3 type.

meow15:12:05

Am curious to know if something similar could be constructed using core.matrix+vectorz-clj?

meow15:12:05

@mikera: I'm adding clisk to my cad code so I can play with it more based on your example. Thank you for making it so easy. simple_smile

meow15:12:26

I guess what I'm really asking is can you recommend an alternative representation for polygon meshes that would support the type of manipulations I'm doing?

mikera16:12:11

Well - I'd probably take a look at using something like a dense Nx3 matrix to represent a large set of points. Would be backed by a single Java array, so very fast for memory access, cache line efficiency etc.

mikera16:12:00

If you want to translate / transform points in bulk that is probably going to be the most efficient representation

meow16:12:20

Yeah, the catmull-clark smoothing function is a good example as it creates new vertices/faces/edges and "moves" previous ones.

meow16:12:57

I also want to do more generative creation of meshes way beyond the simple stuff that I've been doing with platonic solids as seeds.

meow16:12:23

I want to make use of the L-system and cellular automata code I worked on prior to this.

mikera16:12:30

Makes sense. Basically you want arbitrary transformations on point clouds etc.?

mikera16:12:43

And the ability to turn these into solids etc?

meow16:12:45

And creation.

mikera16:12:06

Yup makes sense

meow16:12:15

Yes, I like the idea that they can be 3d printed in real life - so the mesh needs to be watertight, etc.

meow16:12:37

But I also want to create immersive worlds of these things for VR.

mikera16:12:43

You'll need to do quite a bit of index tracking too then

mikera16:12:58

Since a lot of vertices will be shared

mikera16:12:45

I guess some of this depends on how much you are willing to put up with mutability

meow16:12:49

If you look at the gmesh in http://thi.ng it uses a "winged edge data structure" like the Wings3D modeling software. But that's just an overly fancy way of saying that it has some indexes to keep track of its data. There are faces, vertices and edges and everything else is an index.

mikera16:12:21

Yup that is a good way of doing things

mikera16:12:14

It also mirrors how a lot of the operations will actually go to the GPU

meow16:12:04

I just used (op/colorize-clisk clisk/vnoise) on the latest shape I was playing around with. Cool. Got a new toy to play with. Thanks! simple_smile

mikera16:12:35

Cool, enjoy! If you want interesting textures check out tweegeemee on twitter

mikera16:12:47

Nearly all of these work as 3D textures

meow16:12:10

Cursive can't resolve your namespace trickery, sadly. 😞

mikera16:12:45

The only issue I see it that you will need to subdivide a lot if you want the finer details of the textures to show, since we are still only doing per-face colouring

mikera16:12:59

Yes that is a bit of an evil hack....

meow16:12:22

Yeah, I follow that tweegeemee bot - cool stuff.

meow16:12:13

I plan to add per-vertex coloring at some point. Won't be hard to do - just have so many things on my todo list.

meow16:12:57

And I'm still surprised how much I can achieve with just simple coloring of the face.

meow16:12:28

So I'm still playing around with lowpoly and per-face coloring as interesting limitations.

meow16:12:44

@mikera: What is your interest in all of this? Where are you trying to go with your work? And are you interested in any collaboration?

mikera16:12:40

It's more of a fun sideline for me (my main work is around data science / machine learning). happy to collaborate though where I have time.

mikera16:12:58

I also have an interest in game programming, so I'm interested in tools that may help this

meow16:12:59

What I like about this is that its just a bunch of polygons - they can be used for 2d/3d rendering, printing, VR, games, etc.

meow16:12:19

So I have an interest in all of that.

meow16:12:30

What I want to do is create the building blocks that make it easy to create/manipulate/distort polygon meshes in an artistic/inventive way for use in a wide variety of applications.

meow16:12:42

So if I wanted a high-performance "dense Nx3 matrix" as you recommended, where would be the best place to start? Is there anything similar that you could point me to?

mikera16:12:22

Well the raw data structures are already there in vectorz-clj

mikera16:12:37

something like

mikera16:12:46

(use 'clojure.core.matrix)

mikera16:12:10

(def points (new-array :vectorz [100 3]))

mikera16:12:48

Then you can do something like

mikera16:12:22

(defn translate! [pts dx] (add! pts dx))

mikera16:12:08

And other similar bulk operations for scaling etc.

mikera16:12:00

For subdivision etc. you'd need to track indices and "join" extra points onto the array as needed

meow16:12:59

In http://thi.ng the main function is add-face which updates all the indexes as each face is added.

meow16:12:33

Everything is immutable so any mesh op creates a new mesh.

mikera16:12:04

Immutable is nice.... I think that's definitely the best way to go for the overall API

meow16:12:20

A face is a vector of points in counter-clockwise order.

mikera16:12:27

You probably want mutability for some of the internal calculation however, that would be my guess

mikera16:12:05

If performance is an important concern, that is simple_smile

meow16:12:45

That's what I haven't really done with Clojure.

meow16:12:11

I've only been working with clojure for 7 months now.

meow16:12:33

And haven't done any Java - mostly Python.

meow16:12:10

Some js, and lots of other languages before Python, but mostly OO stuff.

meow16:12:25

I will look at vectorz-clj and do some experimenting.

mikera16:12:35

Mutability isn't very idiomatic in Clojure for sure

mikera16:12:57

But it is sometimes justified if you really need the best performance

mikera16:12:18

in core.matrix the API prefers immutable operation like (add a b)

mikera16:12:37

But there are mutable vesions for people who need them, like (add! a b) which mutates a

meow17:12:48

Sweet. I will definitely check it out.

meow17:12:35

Gonna be away for a while soon but will look at this later today or tomorrow.