mxgmn / WaveFunctionCollapse

Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Other
22.99k stars 1.22k forks source link

How to run / develop this project #3

Closed squarism closed 6 years ago

squarism commented 7 years ago

For anyone curious (on a mac):

Run:

$ brew install mono (if you don't have it)
WaveFunctionCollapse $ mcs -pkg:dotnet /reference:System.Drawing.dll *.cs
WaveFunctionCollapse $ mono Main.exe

(it starts working your CPU)

🌻

Rubonnek commented 7 years ago

In Arch Linux the same command works. Only had to install mono:

# pacman -S mono
$ mcs -pkg:dotnet /reference:System.Drawing.dll *.cs
ultrasam commented 7 years ago

How can I run this on a PC?

nilsding commented 7 years ago

@ultrasam I lazied out and created a new C# project in Xamarin Studio (which is pretty much like Visual Studio) and added the C# files which where in the repo. Had to add references to System.Xml and System.Drawing before building.

ultrasam commented 7 years ago

When creating a new C# project in Visual Studio it gives me several options: Windows Forms Application, WPF Application Console Application Shared Project Class Library

Which one should I pick??

nilsding commented 7 years ago

Use a Console Application and remove the Program1.cs file

ultrasam commented 7 years ago

I've got all this errors when I tried to build this, I am new at doing a project in Visual Studio 2015, sorry about that, but any help would be appreciated image

mwaltersva commented 7 years ago

Right click References > Add, select System.Draw

ultrasam commented 7 years ago

Ok, perfect that worked it compiled with no errors, now how do I use the program??

ultrasam commented 7 years ago

Ok, I think I had two programs with the method main and that was causing problems, but now I fixed that and now I am getting the error shown here: image By the way the file samples.xml is there...

dzoba commented 7 years ago

After following @squarism 's directions I am getting

System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000cc] in <93576e487af246b9880ff86779ad60ff>:0
   --- End of inner exception stack trace ---
  at System.Drawing.Bitmap..ctor (System.String filename, System.Boolean useIcm) [0x0002b] in <93576e487af246b9880ff86779ad60ff>:0
  at System.Drawing.Bitmap..ctor (System.String filename) [0x00000] in <93576e487af246b9880ff86779ad60ff>:0
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (string)
  at OverlappingModel..ctor (System.String name, System.Int32 N, System.Int32 width, System.Int32 height, System.Boolean periodicInput, System.Boolean periodicOutput, System.Int32 symmetry, System.Int32 foundation) [0x00041] in <e8e8a4739e4b4f79b85af1dc0961b451>:0
  at Program.Main () [0x000c9] in <e8e8a4739e4b4f79b85af1dc0961b451>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000cc] in <93576e487af246b9880ff86779ad60ff>:0
   --- End of inner exception stack trace ---
  at System.Drawing.Bitmap..ctor (System.String filename, System.Boolean useIcm) [0x0002b] in <93576e487af246b9880ff86779ad60ff>:0
  at System.Drawing.Bitmap..ctor (System.String filename) [0x00000] in <93576e487af246b9880ff86779ad60ff>:0
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (string)
  at OverlappingModel..ctor (System.String name, System.Int32 N, System.Int32 width, System.Int32 height, System.Boolean periodicInput, System.Boolean periodicOutput, System.Int32 symmetry, System.Int32 foundation) [0x00041] in <e8e8a4739e4b4f79b85af1dc0961b451>:0
  at Program.Main () [0x000c9] in <e8e8a4739e4b4f79b85af1dc0961b451>:0```

After googling I don't see a simple answer to that. Any one here encountered/solved it?

EDIT:

I was able to get it to do a bit more by following these commands in addition to what @squarism posted. Not sure if this is the best way, but it seems to be working.

  1. brew cask install mono-mdk
  2. open /usr/local/Caskroom/mono-mdk/4.6.1.3/MonoFramework-MDK-4.6.1.3.macos10.xamarin.universal.pkg
  3. env PATH=/Library/Frameworks/Mono.framework/Commands/:$PATH mcs -pkg:dotnet /reference:System.Drawing.dll *.cs
  4. env PATH=/Library/Frameworks/Mono.framework/Commands/:$PATH mono Main.exe
kchapelier commented 7 years ago

@ultrasam is the samples.xml files actually copied to the build directory ? If it isn't you could try copy pasting it there manually to confirm it fixes the issue you're having. I can't remember what was the setting to include a resource file in the build system of VS though...

EDIT: you will probably have the same issue with all the images

ultrasam commented 7 years ago

well the file is there and I included it in the project: image Here is my project's folder: image

Do you see anything wrong there?

ultrasam commented 7 years ago

Ok I put the samples folder and samples.xml inside the bin/Debug/ folder and it worked!!!, it started creating a bunch of BMPs, now if I want to use my own designs, should I put them on the samples folder??

kchapelier commented 7 years ago

yes, and reference them in the samples.xml file and fiddle with the properties a bit

TheDudeFromCI commented 7 years ago

Is there a pre-compiled version of this? I am very new to C#, and have no idea how to compile or run it. >.>

ultrasam commented 7 years ago

Here: https://dl.dropboxusercontent.com/u/24996373/TileCreation.rar

I hope this helps somebody

TheDudeFromCI commented 7 years ago

Thanks, that's perfect. ^^

ultrasam commented 7 years ago

If you make any new bitmaps or any interesting tileset could you share it, I want to learn

CoenraadS commented 7 years ago

Windows Installation Instructions:

  1. Download NuGet: https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
  2. CMD > nuget install Microsoft.Net.Compilers -Version 1.3.2
  3. CMD > \Microsoft.Net.Compilers.1.3.2\tools\csc.exe *.cs

In my example I had WaveFunctionCollapse-master as my working directory.

NNNenov commented 7 years ago

Thank you all for helping me to understand how to set this up! I am a total amateur, so am playing with this as one. The first thing I tried to do was modify one of the sample images, "flowers", I changed the colours of the petals, and added some other hues of green in the stems. But this results in many "CONTRADICTION"s, it would be really good to have an idea why this is happening, is it because there is no direct chain of same colour pixels, but then, how do the flower heads work? Is there a reference to what parameters are available, or what the parameters demonstrated in samples.xml mean? eg, what does foundation="102" mean?

nylki commented 7 years ago

In Fedora 24 this worked for me (besides mono, mono-data-oracle was needed):

sudo dnf install mono-devel mono-data-oracle
mcs -pkg:dotnet /reference:System.Drawing.dll *.cs
mono Main.exe
mxgmn commented 7 years ago

@NNNenov First, remove the foundation param at all, for default flowers it's hard to set up. Ground in results will be in the middle of a picture, but that's fine. Do contradictions remain? If yes, I need to see your bitmap.

ka-petrov commented 7 years ago

In Ubuntu 16.04 running the command mcs -pkg:dotnet /reference:System.Drawing.dll *.cs

results in the following: error CS1061: Type 'System.Xml.XmlNode' does not contain a definition for 'Get' and no extension method 'Get' of type 'System.Xml.XmlNode' could be found. Are you missing an assembly reference?

Can't figure out what reference am I missing :( including System.Xml changes nothing. Not familiar with mono, but really want to play with the algorithm, pls help :)

kchapelier commented 7 years ago

@imaginary-unit Do you have the Stuff.cs in the same folder ? The extension method in question is here : https://github.com/mxgmn/WaveFunctionCollapse/blob/master/Stuff.cs#L47

ka-petrov commented 7 years ago

@kchapelier Ouch, somehow I didn't include it.. thanks! now it works.

NNNenov commented 7 years ago

@mxgmn yeah it looks like I picked the most fussy one to test first! It works fine without the foundation param. I am curious though what this foundation param means and its input values, in the example its set to 102, but the source image is only 23 pixels high?

mxgmn commented 7 years ago

@NNNenov Foundation is a special case of constraint. I use it in examples like Flowers, City, Platformer to make the ground level be at the bottom of the output. If you delete the foundation param from samples.xml, you'll see that ground appears anywhere in the middle of an output, not necessary at the bottom. Why 102? It goes through input image in a scanline order. First it sees a 3x3 pattern of sky, so 0 is the index of 3x3 blue box. 1 is the index of 3x3 blue box with one pixel of yellow in the bottom right corner, and so on, 102 is the index of top row earth, bottom two rows sky pattern.

BrianLovelace128 commented 7 years ago

I ran the program just fine, but I'm unable to open any of the .bmp files. Image viewer is giving me a message saying "File has bogus header data." Does anyone have any idea why this may be?

kchapelier commented 7 years ago

@BrianLovelace128 Try renaming them to png, this is a known issue which will probably be fixed in the next version ( https://github.com/mxgmn/WaveFunctionCollapse/pull/1 )

NNNenov commented 7 years ago

@mxgmn I thought I understood this but the 3x3 pattern part threw me off a little. so 0 is the index of the top left pixel? and that pixel is the top left anchor/start point of the 3x3 pixel sector? like this? flowers ref So each index is 3x3 pixels, and to set an anchor you count the amount of pixels in scanline order, then quanitze/divide by 3?

nanodeath commented 7 years ago

@NNNenov I think so, but it only counts unique 3x3 patterns. If you have a solid block of gray that's 9x9, it'll only yield a single index value. Look for T in the code.

Basically, without some sort of visual editor tool, I don't think it's actually practical to try to set our own foundation values (yet).

mxgmn commented 7 years ago

@nanodeath @NNNenov Actually, now I see a better way to set it for flowers: foundation="-4".

mxgmn commented 7 years ago

@NNNenov Your picture is not completely right. 0 is not the index of top left pixel. 0 is the index of the whole 3x3 blue block. A mental unit test: 6 is the index of blue 3x3 block with one yellow pixel in the middle row right column.

nanodeath commented 7 years ago

Heh, that was a bit of a brain bender. The top left corner of "6" is at (2,1), right? (assuming 0-based indexing)

gliptak commented 7 years ago

Current HEAD compiles on Ubuntu 16.04:

cat /etc/lsb-release
sudo apt install mono-devel
mcs -pkg:dotnet /reference:System.Drawing.dll *.cs
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mono-devel is already the newest version (4.2.1.102+dfsg2-7ubuntu4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Model.cs(18,29): warning CS0649: Field `Model.limit' is never assigned to, and will always have its default value `0'
Compilation succeeded - 1 warning(s)
mxgmn commented 7 years ago

@nanodeath Yes, if I counted them right. Checked it in my gui: correct.

NNNenov commented 7 years ago

So if the image has multiple 3x3 sectors with identical pixels, they are all treated with the same index, so to figure out which sector the foundation should be at, I need to check how many unique 3x3 sectors there are, in a scan-line order? @mxgmn would you or @nanodeath mind marking a few numbered 3x3 sectors over the sample image I linked to, so I can see what you mean and get a better idea?

nanodeath commented 7 years ago

@NNNenov here, I've annotated the first two rows based on the top-left corner. (in hex) flowers_annotated

mxgmn commented 7 years ago

@NNNenov Yes.

@nanodeath @NNNenov This is the correct ordering with symmetry=1. With symmetry=2 ordering is a little different, but anyway it illustrates the idea better then symmetry=2, it's just to weird then, no need to re-upload. Here I made a picture with big digits (and still symmetry=1) to illustrate that indices enumerate whole 3x3 blocks.

nanodeath commented 7 years ago

Okay, that took me a little while to figure out. From my symmetry=1 image, because 1 and 5 are mirror images of each other, 5 doesn't get generated at all in the symmetry=2 case (rather, 5 could mean something totally different and unrelated). Correct?

mxgmn commented 7 years ago

@nanodeath Yes, it would be 0, 0, 1, 3, 5, 4, 2, 0, 0, 0, 1, ...

NNNenov commented 7 years ago

I think I understand too.. so now I'm wondering @mxgmn how did you calculate the foundation sector 102 for the flowers image? Did you have to use some sort of function to get the sector based on target pixel?

nanodeath commented 7 years ago

@NNNenov he has a GUI tool I think. FWIW, I was planning on making my own little tool using JavaFX to do something similar.

If anyone else is curious about what symmetries are and can be, it can be any value between 1 and 8 and is captured here. 1 = original, 2 = reflected, 3 = rotated, 4 = rotated and reflected, etc.

mxgmn commented 7 years ago

@NNNenov We know what T is (T=106 for flowers, you can just print T in the constructor), so we can just count from the back, ground = 106 - 4 = 102. I myself have a gui that just tells me the index when I point a mouse on a pixel.

nanodeath commented 7 years ago

You can also use negative numbers (e.g. -1 is the last unique pattern), so if your unique pattern happens to be near the beginning or end, you can just guess based on that. Granted, it gets confusing when you factor in reflections and rotations...

hemik1 commented 7 years ago

Hey! Awesome piece of code! I managed to plug it into my unity voxel engine, got some fun results. I was wondering if you could elaborate on the 3d approach, those screenshots you shared look quite amazing. Will you be sharing a 3d repo by any chance?

mxgmn commented 7 years ago

@hemik1 Thank you! Show the results then. Of course, 3d repo will also be public. This will not happen very soon though.

NNNenov commented 7 years ago

It's been great fun playing around with this. I would like to try and make the tiled model output a list containing the tile type and orientation (where applicable) at each tile index, for parsing to 3D software e.g: tile[index] = tileShape[angle] // or tile[x][y] = tileShape[angle so this data can be parsed into any 3D software to make a grid of "3D" tile shapes(its still technically 2D, but I can replace the shapes with objects from a range). Like I mentioned earlier, the code is beyond me, but I'd love to learn, maybe if you see how crazy my current plan is someone will help.. So my approach was going to be caveman style: draw 3 pixels per tile with fixed alignment, with different colour based on tile type, then use a script to scan the pixel output of the program to calculate orientation and derive tile type based on the pixel colour.. I know this is a bit ridiculous, but its simply because the current code is just too complex for me to understand!

mxgmn commented 7 years ago

@NNNenov I see. Your approach is the best that could be done fast. I'd suggest only using 2 colored pixels placed in a non-symmetric way instead of 3, otherwise you can't distinguish between 2 mirror symmetries. And, if you work with the C# code, using bitmapData directly instead of scanning a saved bitmap.

Returning an array of tiles together with rotations can't be implemented elegantly in this version, because it forgets all symmetry information after executing the constructor. This way I can keep Propagate() methods short and Observe() method single for all models. Maybe @nanodeath could implement the direct output of tiles + rotations since he is building an all-around library.

NNNenov commented 7 years ago

I'm not sure I follow you re: symmetry, in the samples I didn't see any simple tiled configuration with symmetry as a variable, I thought that was just for the overlapping model? Can simple tiled model mirror any tiles?