threedle / GeoCode

GeoCode maps 3D shapes to a human-interpretable parameter space, allowing to intuitively edit the recovered 3D shapes from a point cloud or sketch input.
374 stars 25 forks source link

question about how to do shape mixing and #13

Closed rainforeast closed 1 year ago

rainforeast commented 1 year ago

hello, thanks for sharing, I am very interested in your work, but I know very little about blender geometry node.I hope these are not dull questions

  1. I'd like to know how to use the code to generate a new blend field that can be edited with human-interpretable parameters in the blender.
  2. Also, I'd would like know if shape mixing is possible in blender or if a new code is required to achieve this goal.

I hope to get your reply^-^

ofekp commented 1 year ago

All shape mixing operations are done within Blender. After you open blender, go to the scripting workspace: image Then, you can get the python path to a single Geometry Nodes parameter by right clicking the parameter's value: image

The better option will be to do it by code. Below is a quickly written code to do that.

from dataset_generator.dataset_generator import save_obj_label
from common.bpy_util import save_obj, select_shape, select_objs, get_geometric_nodes_modifier, refresh_obj_in_viewport
from common.file_util import get_recipe_yml_obj
from common.input_param_map import load_shape_from_yml, get_input_param_map

def save_current_shape_and_label(dir, file_name):
    # select the object in blender
    obj = select_shape()
    # get the geometric nodes modifier fo the object
    gnodes_mod = get_geometric_nodes_modifier(obj)
    save_obj_label(gnodes_mod, dir.joinpath(f"{file_name}.yml"))
    dup_obj = save_obj(dir.joinpath(f"{file_name}.obj"))
    select_objs(dup_obj)
    return dup_obj

def load_sample(yml_file_path, recipe_file_path):
    obj = select_shape()
    # get the geometric nodes modifier of the object
    gnodes_mod = get_geometric_nodes_modifier(obj)
    recipe_yml_obj = get_recipe_yml_obj(recipe_file_path)
    input_params_map = get_input_param_map(gnodes_mod, recipe_yml_obj)
    try:
        load_shape_from_yml(yml_file_path, input_params_map, ignore_sanity_check=True)
        refresh_obj_in_viewport(obj)
    except Exception as e:
        print(repr(e))

Pseudo code for main:

  1. save two (or more) shapes using save_current_shape_and_label
  2. create a mixed shape by selecting some parameters from each of the shapes you saved
  3. use load_sample to load the newly created yml label file.

Note that recipe_file_path is in the following directory: https://github.com/threedle/GeoCode/tree/main/dataset_generator/recipe_files

With the hope that I correctly understood the first question, the code does not generate new Blend files, you'll have to follow the guidelines depicted in the paper and you can reuse parts from the existing Blend files to build a new shape program. I hope this helps.

rainforeast commented 1 year ago

I appreciate your clear explanation very much. That is very helpful.(' V ')