action-script / ofxWFC3D

Wave Function Collapse 3D | openFrameworks Addon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Port code to c++ without OpenFramework

geotyper opened this issue · comments

Port your code to c++ without OpenFramework and try to start simple example.
have next picture
Screenshot at 2020-04-19 18-22-33
Think that have some errors in code because to many open lines or it normal?
Can you share picture of first example to compare results.

That is look when "only turns" option choose
Screenshot at 2020-04-19 19-00-05

By the rules and models of the basic example, those results are not not normal.

WFC_basic_02
WFC_basic_01

Check the axis orientation of your 3D system. At OF Y goes +UP, X goes +RIGHT and Z goes -FORWARD. Could happen that the 3D assets have y and forward wrong oriented for your implementation.

Thanks for prompt answer, make procedural 3D assets, try to save orientation as in your example
Use BGFX for render, looks at orientation again.
And you dont use this parameters in XML file:
auto xmla_minheight = xmln_tile.attribute("min-height");--->0
auto xmla_maxheight = xmln_tile.attribute("max-height");----> max.z

Screenshot at 2020-04-19 20-27-10
Thats is right orientation?

And another question, about parent node
world_node.position=Vec3(1.f, 0.f, 0.f); this coord of parent node

 tile_node.setParent(parent_node);
 tile_node.position=Vec3(x*grid_size.x, y*grid_size.y, z*grid_size.z);
 tile_node.rotateDegree=ofToInt(tile_cardinality[1])*90.0f;

when we rotate, it rotated around center of mesh or center plus coord parent node?

axis z-forward direction to screen?
on picture from screen Z
Screenshot at 2020-04-19 22-04-25

Thanks for prompt answer, make procedural 3D assets, try to save orientation as in your example
Use BGFX for render, looks at orientation again.
And you dont use this parameters in XML file:
auto xmla_minheight = xmln_tile.attribute("min-height");--->0
auto xmla_maxheight = xmln_tile.attribute("max-height");----> max.z

min-height and max-height properties are processed and used on the code. The basic example does not utilize those features. However, the advance example uses the properties.

And another question, about parent node
world_node.position=Vec3(1.f, 0.f, 0.f); this coord of parent node

 tile_node.setParent(parent_node);
 tile_node.position=Vec3(x*grid_size.x, y*grid_size.y, z*grid_size.z);
 tile_node.rotateDegree=ofToInt(tile_cardinality[1])*90.0f;

when we rotate, it rotated around center of mesh or center plus coord parent node?

The line <tile_node.rotateDeg(ofToInt( tile_cardinality[1])*90.0f, axis_y );> : rotates the tile around the model's origin. Rotations applied to the parent node will take the parent node origin as transformation point. On render, you can compound the matrices of the nested nodes like a transformation tree.

Screenshot at 2020-04-19 20-27-10
Thats is right orientation?

On OF 2D screen space, the coordinate origin is top left and Y is oriented downwards to positive.
As 3D OFNode, the center of coordinates is 0,0 (center of screen) and the Y axis orientation is UP.
In both cases, Z goes positive towards the camera and negative forward.

But this does not matter. It all depends on the coorinate system and axis orientation you use on your render logic and the 3D models. Take the simetry as 2D reference and match the 3D models with that orientation.

Thanks for your support, change degree of rotation to minus degree, and all look better )
Screenshot at 2020-04-20 08-41-04

And If use cross need to add it item and neighbors to XLM? code have this simmetry
Screenshot at 2020-04-19 20-07-59
to XLM?

if (tile_name == ground_name) ground_id = num_patterns;
if (tile_name == surround_name) surround_id = num_patterns;
When give some names to ground or surround algorithm return -1/ or nothing
How to close borders as in your screen short?

And If use cross need to add it item and neighbors to XLM? code have this simmetry
Screenshot at 2020-04-19 20-07-59
to XLM?

Yes, every tile has to be declared in the XML. It does needs a symmetry and neighbors that defined the rules for the WFC.
At the ofxWFC3D, I implemented a new kind of symmetry (called "+"). The symmetry has nothing to be with the shape of the 3D model but the relationship with the neighbors, rotations and the location possibilities.

if (tile_name == ground_name) ground_id = num_patterns;
if (tile_name == surround_name) surround_id = num_patterns;
When give some names to ground or surround algorithm return -1/ or nothing
How to close borders as in your screen short?

ground_name will use such tile as gorund and will then force the neihbord tiles to be related to that ground rules.
surround_name will place a tile surrounding the 4 walls of the grid and will force the WFC to calculate the result based on that rules.
Because the XML rules of the basic example are set to not connect an open pipe into a empty tile, by surrounding the grid with empty tiles, it will force the WFC to find alternatives where the borders of the pipes are closed and connected to each other.

If the WFC returns null or negative, does it mean has not found a solution. It may be due conflits on the XML rules or at the initialization parameters. If using a ground tile, make sure such tile rules match the setup and other tiles can be placed on top of such tile while not blocking other neighbors.

Imagine trying to solve a sudoku when there is already placed conflicting numbers that makes the sudoku being impossible to be solved.

Thanks again for detailed answers, think that in simple example all works
Screenshot at 2020-04-20 21-04-09

At the ofxWFC3D, I implemented a new kind of symmetry (called "+"). The symmetry has nothing to be with the shape of the 3D model but the relationship with the neighbors, rotations and the location possibilities.

But what about symmetry (called "+"). It can be related with shape or as you write only for neighbors?

and one, more:
float bound_width=10, bound_height=22, bound_length=10;
if bound height greater than width,length algorithm lose it possibility to find good result, try with different tile types and dimensions (5,10,5 for example)

But what about symmetry (called "+"). It can be related with shape or as you write only for neighbors?

Tiles symmetry:
https://www.dropbox.com/s/zeiat1w8zre9ro8/Knots%20breakdown.png?dl=0
The "+ symmetry" is an special case that actually only use rotations and no symmetry.

and one, more:
float bound_width=10, bound_height=22, bound_length=10;
if bound height greater than width,length algorithm lose it possibility to find good result, try with different tile types and dimensions (5,10,5 for example)

You are right, that was a bug.
It has been fixed on 2042eef