p-hofmann / SMBEdit

StarMade Blueprint Editor
5 stars 1 forks source link

Command line voxelization #21

Closed Septaris closed 7 years ago

Septaris commented 7 years ago

Modifications

Usage

Once the package is installed with pip, the list of subcommands is available using smb -h:

usage: smb <command> [<args>]

 -- Available subcommands --

edit:
        Edit an existing blueprint

voxelize:
        Create a blueprint from a 3D model (obj/stl)

Create/Edit StarMade Blueprints

positional arguments:
  command     Subcommand to run

optional arguments:
  -h, --help  show this help message and exit

smb edit is an alias for smbedit whereas smb voxelize is the new subcommand to voxelize 3D models:

usage: smb [-h] -i PATH_INPUT -r RESOLUTION [-b BLOCK_ID] -o PATH_OUTPUT
           [-a {x,y,z}] [-n {0,1,2,3}] [-et {0,1,2,3,4}]

Create a blueprint from a 3D model (obj/stl)

optional arguments:
  -h, --help            show this help message and exit
  -i PATH_INPUT, --path_input PATH_INPUT
                        '*.obj' or '*.stl' file path
  -r RESOLUTION, --resolution RESOLUTION
                        Voxelization resolution
  -b BLOCK_ID, --block_id BLOCK_ID
                        Block used to voxelize the model [default: 598 (Grey
                        Hull)]
  -o PATH_OUTPUT, --path_output PATH_OUTPUT
                        Output directory of the blueprint
  -a {x,y,z}, --rotation_axis {x,y,z}
                        The model is rotated in the plane perpendicular to the
                        given axis
  -n {0,1,2,3}, --rotation_number {0,1,2,3}
                        Number of times the model is rotated by 90 degrees
                        clockwise
  -et {0,1,2,3,4}, --entity_type {0,1,2,3,4}
                        Change entity type to: 0: Ship 1: Shop 2: Space
                        Station 3: Asteroid 4: Planet

Example

Model voxelization with a 270 degrees clockwise rotation around x axis:

smb voxelize -i my_model.stl -r 500 -o .\my_blueprint\ -a x -n 3

and smoothing of the new blueprint:

smb edit .\my_blueprint\ -o .\my_blueprint_smooth\ -aw -at -ah
p-hofmann commented 7 years ago

Looks good. I like the 'cli' solution Could you make this pull request for the 'develop' branch? I notices some issues with the voxelisation and I want that fixed before I merge more of it into the master. Looks like I might have to scrape off a thick layer of rust from my linear algebra education for that, how is yours?

Septaris commented 7 years ago

My bad for the master branch ^^

For the cli it's just a first draft of what we can do with commands/subcommands. We can go further with a task system, in which we decouple the different actions in sub-commands and combine them using a pipe like syntaxe.

I was not bad in algebra but I have not practiced since a long time :)

p-hofmann commented 7 years ago

So much for algebra, was an weird floating point issue.

Do you happen to have gcc installed on a windows 64 bit system? I would like to offer the c library if possible.

'PyVoxelizer/voxlib/voxelintersect/triangleCube.c'

gcc -Wall -fPIC -O2 -c triangleCube.c gcc -shared -o triangleCube.so triangleCube.o

Septaris commented 7 years ago

and voila (I hope it'll work^^)

Compiler version:

gcc.exe (i686-posix-sjlj-rev0, Built by MinGW-W64 project) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

triangleCube.zip

p-hofmann commented 7 years ago

Thank you! I pushed it into the develop branch of PyVoxelizer. Would be great if you could give it a try. I put a try catch around the critical parts, but I have no proper way of testing if bad errors are caught properly. I plan to make a forum post about SMBEdit at some point, in the hope of getting more feedback.

Septaris commented 7 years ago

Everything seems to work with the latest version of smbedit / voxlib / meshreader (Win10, 64bit). I have got just some warnings during obj reading [ObjReader] WARNING: Unknown key: s (cf the zip file) vorastra.zip