Jump to content

konstantin magnus

  • Content count

  • Donations

    0.00 CAD 
  • Joined

  • Last visited

  • Days Won


Everything posted by konstantin magnus

  1. "Make circle" SOP?

    How can I access the new "make circle"-function procedurally? see: http://www.sidefx.com/forum/topic/44697/
  2. "Make circle" SOP?

    Thank you again @petz for posting a mathematical solution. I am currently trying to apply it to another mesh (fig. 1). Unfortunately most of the points get collapsed (fig. 2). Is there anything I am missing out? Meanwhile I was trying to come up with a simple solution on my own (fig. 3), which is not unifying the distances between the points along a circle but is averaging out their distance towards the center. Unfortunately I would not quite know how to flatten my points on an oblique plane based on their average normal (fig. 4). human.hiplc
  3. Extrude by colour

    It is better to paint on a black surface right away, because that way all color channels are initially set to 0. After painting you should promote colors to primitives, because this is what primitive extrude is working with. If however you have chosen to paint red on white, the red channel will be set to 1 everywhere. Red = 1,0,0 and White = 1, 1, 1. Thats why the green or blue channel is more distinctive here: Set your primitive wrangle to f@r = 1.0 - @Cd.g; so its able to tell where red is being used. Inside the primitive extrude set 'distance' to something larger than 0 and set 'distance scale' to r. exturde by color_corr.hiplc
  4. VEX selecting border edges

    Set a normal node to 'points' and put this in an attribute wrangle: if( max( abs(v@N) ) < 0.9 ){ int nbs[] = neighbours(0, @ptnum); foreach(int nb; nbs){ if(nb > @ptnum){ vector nml = point(0, 'N', nb); setedgegroup(0, 'outer_edges', @ptnum, nb, max(abs(nml)) < 0.9); } } } box_edges.hiplc
  5. Connecting points in vex

    Leaving out the constraint about no PC2 point used twice, it would be just this between both point clouds: int connections = 10; for(int i = 0; i < connections; i++){ int pt_PC2 = int( rand(@ptnum + 45 * i) * npoints(1) ); vector pt_pos = point(1, 'P', pt_PC2); int pt_add = addpoint(0, pt_pos); int prim_add = addprim(0, 'polyline', @ptnum, pt_add); } With sorting out points however you will probably need a sequentiell approach using arrays. connect_point_clouds.hiplc
  6. Convert Slice images to Volume

    I just created a tutorial on how to convert a sequence of slice images to a volume using VEX. slices_to_volume.hiplc
  7. Blueprints to 3D Mesh

    Here is a concept for turning blueprints into simple 3d meshes. Its basically carving silhouettes into a volume. After getting the aspect ratio for defining the volume´s dimensions ... res_front = hou.imageResolution(img_front) res_side = hou.imageResolution(img_side) res_top = hou.imageResolution(img_top) ratio_side = res_side[1] / float(res_side[0]) ratio_top = res_top[1] / float(res_top[0]) geo.addAttrib(hou.attribType.Global, 'ratio_s', ratio_side, create_local_variable=False) geo.addAttrib(hou.attribType.Global, 'ratio_t', ratio_top, create_local_variable=False) ... a wrangle is carving the silhouettes into the volume from all three sides: vector bbox = relbbox(0, v@P); float mask_front = vector(colormap(image_front, bbox.x, bbox.y)).x; float mask_side = vector(colormap(image_side, bbox.z, bbox.y)).x; float mask_top = vector(colormap(image_top, bbox.x, bbox.z)).x; f@density = min(mask_front, mask_side, mask_top); The rest is a matter of converting to polygons, smoothing and remeshing. blueprint_to_geo.hiplc blueprints.zip
  8. Generating a grid of points based on text.

    You could blast unnecessary points from your grid based on their instance number attribute and assign the models with copy to points. I added the HIP file to the post above.
  9. Generating a grid of points based on text.

    Hi Thomas, here is some Python code to create a grid based on a multi-line string: node = hou.pwd() geo = node.geometry() text = node.evalParm('text') lines = text.splitlines() numbers = [map(int, line.split(';') ) for line in lines] geo.addAttrib(hou.attribType.Point, 'instance', -1) for row, n in enumerate(numbers): for col, value in enumerate(n): pos = (col, 0.0, row) pt_add = geo.createPoint() pt_add.setAttribValue('instance', value) pt_add.setPosition(pos) copy_to_grid.hipnc
  10. Changing Color components

    In a point wrangle create an amount parameter (line 1) and convert the color values to HSV (line 2). Choose a range within the hue spectrum that is supposed to change (line 3). Multiply it by the amount and add the result to the hue component of the HSV color (line 4). Convert the color vector back to RGB (line 5). float amount = chf('hue_shift'); vector col_hsv = rgbtohsv(v@Cd); float range = chramp('mask_by_hue', col_hsv.x); col_hsv.x += amount * range; v@Cd = hsvtorgb(col_hsv); change_color_component2.hipnc
  11. Create a Landscape from Irregular Points using Multivariate Interpolation

    I just found out about the radial basis function (RBF) in Scipy.interpolate, which does an even better job at interpolating between irregular points. As it does not use delaunay, it also lost the trianglish appearance it had before. RBF looks way smoother than what you´d get from Attribute Transfer SOP, too. Btw: Does someone know, how to make the same code work with vector arrays in NumPy? I tried it in the commented lines, but currently I have to use three separate arrays for each color channel and therefore call each function three times, as well : ( import numpy as np from scipy.interpolate import griddata import scipy.interpolate as interp node = hou.pwd() geo1 = node.geometry() inputs = node.inputs() geo2 = inputs[1].geometry() method_nr = node.evalParm('method') method_names = 'multiquadric,inverse_multiquadric,gaussian,linear,cubic,quintic,thin_plate'.split(',') method_str = method_names[method_nr] grid_x = np.array(geo1.pointFloatAttribValues('px')) grid_z = np.array(geo1.pointFloatAttribValues('pz')) color_r = np.array(geo2.pointFloatAttribValues('cr')) color_g = np.array(geo2.pointFloatAttribValues('cg')) color_b = np.array(geo2.pointFloatAttribValues('cb')) #color = np.array(geo2.pointFloatAttribValues('Cd')) #np.reshape(color, (30, 3)) pos_x = np.array(geo2.pointFloatAttribValues('px')) pos_z = np.array(geo2.pointFloatAttribValues('pz')) rbf_red = interp.Rbf(pos_x, pos_z, color_r, function=method_str) rbf_green = interp.Rbf(pos_x, pos_z, color_g, function=method_str) rbf_blue = interp.Rbf(pos_x, pos_z, color_b, function=method_str) #rbf_color = interp.Rbf(pos_x, pos_z, color, function=method_str) smooth_rbf_red = rbf_red(grid_x, grid_z) smooth_rbf_green = rbf_green(grid_x, grid_z) smooth_rbf_blue = rbf_blue(grid_x, grid_z) #smooth_rbf_color = rbf_color(grid_x, grid_z) geo1.setPointFloatAttribValuesFromString("clr_r", smooth_rbf_red.astype(np.float32)) geo1.setPointFloatAttribValuesFromString("clr_g", smooth_rbf_green.astype(np.float32)) geo1.setPointFloatAttribValuesFromString("clr_b", smooth_rbf_blue.astype(np.float32)) #geo1.setPointFloatAttribValuesFromString("Cd", smooth_rbf_color.astype(np.float32)) scipy_grid_to_color_points.hiplc
  12. This is an example for building landscapes from irregular points using SciPy. import numpy as np from scipy.interpolate import griddata # FIRST INPUT: REGULAR GRID node = hou.pwd() geo1 = node.geometry() grid_x = np.array(geo1.pointFloatAttribValues("px")) grid_y = np.array(geo1.pointFloatAttribValues("py")) grid_z = np.array(geo1.pointFloatAttribValues("pz")) # SECOND INPUT: RANDOM POINTS inputs = node.inputs() geo2 = inputs[1].geometry() val_x = np.array(geo2.pointFloatAttribValues("px")) val_y = np.array(geo2.pointFloatAttribValues("py")) val_z = np.array(geo2.pointFloatAttribValues("pz")) # MULTIVARIATE INTERPOLATION grid_y = griddata( (val_x, val_z), val_y, (grid_x, grid_z), fill_value=0.0, method='cubic' ) # methods: nearest, cubic, linear # NEW HEIGHT POSITIONS ON GRID geo1.setPointFloatAttribValuesFromString("py",grid_y.astype(np.float32)) scipy_grid_to_points.hiplc
  13. Print Label

    Thanks Atom! node = hou.pwd() geo = node.geometry() text = node.parm('text').eval() res = len(text) node.parm('result').set( str(res) )
  14. Print Label

    How can I print an uneditable result to a label (or any other suitable text field)?
  15. Python: Loop delete geometry

    I want to export single tiles of a grid by their id attribute with Python. Because saveToFile() is lacking any filter options, I am trying to use a loop for deleting all redundant primitives before each export. Unfortunately once primitives have been deleted for the first time, they are gone for all subsequent loops, too. node = hou.pwd() geo = node.geometry() dir_exp = node.evalParm('dir_export') id_values = geo.primIntAttribValues("id") id_count = len(set(id_values)) # is there a more hou way to count unique attribute values? for iteration in range(id_count): geo_change = geo path_export = dir_exp + 'segment' + str(iteration) + '.obj' prims = [p for p in geo_change.prims() if p.attribValue('id') != iteration] geo_change.deletePrims(prims) # how can I keep the full geo data for the remaining loops? geo_change.saveToFile(path_export) How can I keep the full geometry for each loop? And are there any better ways to export geometry parts based on attributes with Python? landscape_slice_export.hiplc
  16. 'Dart throwing' algorithm

    Thank you Tomas! I put together a little video tutorial summing it all up: https://www.youtube.com/watch?v=Y1UC3T9l15U
  17. 'Dart throwing' algorithm

    I just tried it with a SOP Solver, scattered random positions with uvsample() and then filter them out by their distance to the closest of nearpoints(). vector pos_uvw = rand(@Time) * {1, 1, 0}; float dist_uv = xyzdist(2, pos_uvw); if( dist_uv < 1e-5 ){ vector pos_geo = uvsample(1, 'P', 'uv', pos_uvw); float rad_pt = fit01( rand(@Time + 45), 0.02, 0.1 ); int pts_close[] = nearpoints(0, '!mesh', pos_geo, 0.5, 2); vector pos_close = point(0, 'P', pts_close[1]); float dist_close = distance(pos_geo, pos_close); float rad_close = point(0, 'pscale', pts_close[1]); float t = dist_close - rad_close - rad_pt; if( len(pts_close) <= 0 || t > 0.0 ){ int pt_add = addpoint(0, pos_geo); setpointattrib(0, 'pscale', pt_add, rad_pt, 'set'); } } While it does some filtering, it still produces fairly obvious intersections: Is there something about the SOP solver I dont understand (maybe some syncing issue?) or what did I miss here? dart_throwing.hiplc
  18. Sticking object to mesh

    This tutorial explains it starting at 34:28: https://vimeo.com/307156961
  19. Overlapping Curves Offset with PointCloud?

    You can build bridges over bridges by stacking straight lines and using the number of ray hits downwards as height: // The space around the lines float tol = chf('tolerance'); // Attributes we dont use, but are required for the intersect_all function. vector ray_pos[]; int ray_prim[]; vector ray_uvw[]; // Ray direction and length reaching to the floor. vector dir = v@P * {0, -1, 0}; // Slightly shifted starting position so it doesnt shoot itself. vector pos = v@P - {0, 0.1, 0}; // Shooting ray and counting hits on other lines. int rays = intersect_all(0, pos, dir, ray_pos, ray_prim, ray_uvw, tol, 0.01); // The number of hits is used to stack points of lines on top of each other. v@P.y = float(rays) * 0.1; bridges_over_bridges.hiplc
  20. Overlapping Curves Offset with PointCloud?

    You could ask whether nearpoints() within a certain radius come from a higher numbered primitive. And if they do, apply the radius minus their distance to your point´s height. float r = chf('radius'); int pts_near[] = nearpoints(0, v@P, r); float rise = 0.0; foreach(int pt; pts_near){ int pr_other = pointprims(0, pt)[0]; if(pr_other > i@primnum){ vector pos = point(0, 'P', pt); float dist = r - distance(v@P, pos); if(dist > rise){ rise = dist; } } } v@P.y = rise; bridges.hiplc
  21. Batch opening and saving *.obj files

    Thanks for the hint, Alex! Seems like you can do batch jobs completely within a python node : ) This one for example scales all OBJ files from a folder and its subfolders and saves them to another location: import os geo = hou.pwd().geometry() scale = hou.evalParm('scale') dir_imp = hou.evalParm('dir_import') dir_exp = hou.evalParm('dir_export') for root, dirs, files in os.walk(dir_imp): for file in files: if file.endswith('.obj'): path_import = os.path.join(root, file) path_export = dir_exp + file geo.loadFromFile(path_import) for point in geo.points(): pos = point.position() * scale point.setPosition(pos) geo.saveToFile(path_export)
  22. Batch opening and saving *.obj files

    How do I batch open randomly named OBJ-files from a folder on my harddisk and how can I batch save those in a different folder while keeping their file names?
  23. vex - arrays

    Numpy also seems to be suitable for comparing arrays, e.g. setdiff1d() for extracting "left-overs". import numpy node = hou.pwd() geo = node.geometry() arr1 = geo.intListAttribValue('arr1') arr2 = geo.intListAttribValue('arr2') AB = numpy.setdiff1d(arr1, arr2) BA = numpy.setdiff1d(arr2, arr1) geo.addAttrib(hou.attribType.Global, 'arr_AB', AB, create_local_variable=False) geo.addAttrib(hou.attribType.Global, 'arr_BA', BA, create_local_variable=False) I just dont know how to create proper array attributes with Python. Currently it returns just a bunch of integer attributes
  24. It works if you are more explicit about whats a vector and whats a float: eg. v@target instead of just @target. v@a=normalize(v@target-v@P); f@angle=dot(v@N, v@a); v@Cd=vector(f@angle); Also it does not make sense to put vector pt into the for loop, when there is nothing to change. vector pt = point(1, "P", 0); for( int i = 0; i < npoints(0); i++){ setpointattrib(0, "target", i, pt, "set"); } May I ask why you want to put this into a detailwrangle with a for loop after all? The thought behind a point wrangle is already that its running over all points.
  25. New Color Schemes

    I know its unusual and probably a bit retro, but at daytime or during presentations its sometimes good to have a little more contrast, I think.