ikarth / wfc_2019f

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

porting to Sverchok

Durman opened this issue · comments

Hello. I'm thinking about porting this code into node editor Sverchok addon for Blender. I think it will let to familiarize more people (some Blender users) with this amazing algorithm.

2020-06-05_22-12-22

I investigated the code a little and have found that it has dependencies which Blender Python interpreter does not have. Fortunately there is numpy by default at least in Blender.

I have started with this repository it has very simple code.
https://github.com/robert/wavefunction-collapse
But performance is lousy. I'm going to replace parts of the code by code from this repository if it will be possible to move everything to numpy module.

Hi, I have just played around this lib. For what i understand, only numpy and scipy (for sparse matrix) are mandatory. It looks like others could easily be removed or replaced like for example imageio if there is an equivalent in Blender, or if you don't need to read/write images.

Hello. Cool. Then I just have to override scipy module.

Actual result.
2020-06-07_15-45-52

I did not use code of this repository yet. Will get closer look now.

I can't make it work yet. Most likely because I just replace csr_matrix with numpy matrix.

adjMatrices[d] = sparse.csr_matrix(m)

adjMatrices[d] = m

Only works with simplest samples now.
2020-06-07_21-59-04

The actual solver doesn't need sparse matrices--I was using them to save memory, but in actual practice I don't think it saves enough to be worthwhile.

If you look in the tensor branch, it converts the sparse matrix into a standard numpy matrix. It'd be better to just have it be a dense matrix to begin with, but I was modifying the existing code for other reasons so it doesn't do that right now.

The images in the samples folder (from the original WFC git repo) are good for testing with. The most common issue I see is when something gets transposed or flipped.

A little move. But performance is too slow I guess. It took 1750 iteration to solve this pattern (50x50 output). Something definitely works incorrect because I can't make standard samples work. I cleaned up a lot of code and rewrite a little bit. Probably I did something wrong. I have to debug it somehow now.

2020-06-09_14-09-34

@ikarth Could you explain how this should work. I don't understand what is happening with supports variable. I think that it should detect which patterns are not suitable for current pixels but how it can be done during this operations.

supports[d] = (adj[d] @ shifted.reshape(shifted.shape[0], -1)).reshape(shifted.shape) > 0

Type of adjacent matrix and shifted wave arrays are bool. Dot product of two bool matrixes returns bool matrix. Why is comparison with zero in the end then? It does not have sense. I do not see how it should work.

I had to test the implementation before diving deep into it. Actually current performance is really disappointing. It takes about a minute to create city 48x48 in average on my machine.

I have found implementation on java script with interactive demos.
https://github.com/kchapelier/wavefunctioncollapse

Generation of the same picture takes about several seconds. So I don't think that on Python it should take much more. Probably conception of algorithm of current implementation is wrong and some other solution should be researched.