0
$\begingroup$

I really need your help. I am looking at morphing, say a cube into a sphere. I wish to do this by scaling/transforming specific points of the cube to new points (with coordinates) in order to form a sphere. I apologise for the lack of clarity. In a nutshell im looking to perform mesh transformation with coordinate values for each point of one object to form another object, after which I will animate.

If this can be performed with Python or geometry nodes or any other way, please let me know. This is for a personal project. Feel free to share any methods similar to what I am describing.

$\endgroup$
7
  • $\begingroup$ Cast modifier? Are your objects only cubes and spheres or others? $\endgroup$
    – lemon
    Feb 6, 2023 at 16:29
  • $\begingroup$ Thats like a base model example. Im looking at doing complex shapes $\endgroup$
    – O I
    Feb 6, 2023 at 16:33
  • $\begingroup$ If your objects have the same amount of vertices, you can use shape keys to do that. But the aspect of the result will depend a lot on the vertex orders. $\endgroup$
    – lemon
    Feb 6, 2023 at 16:36
  • $\begingroup$ alright thanks. Do shape keys work if i want to displace them with specific coordinates for specific points? $\endgroup$
    – O I
    Feb 6, 2023 at 16:39
  • $\begingroup$ with shape keys, in theory yes (either manually or using python), but choosing the vertex mapping between the two objets is complex. If this mapping is random you'll have things like that: i.sstatic.net/qbTFY.gif $\endgroup$
    – lemon
    Feb 6, 2023 at 16:45

1 Answer 1

2
$\begingroup$

Alternative to using shape keys, vertex coordinates are directly keyframable. If v is a vertex of a mesh, you can use v.keyframe_insert('co', frame = some_num). Looping through the vertices of a mesh and keyframing each one's initial and final coordinates is a way to morph the mesh.

Take a cube, go into edit mode, select all its faces at once, and then do a few subdivisions. Next, try the following script:

import bpy

cube = bpy.data.objects['Cube']

verts = cube.data.vertices

for v in verts:
    
    v.keyframe_insert('co', frame = 1)
    
    # setting a v.co or vector equal to itself divided by its magnitude gives
    # the vector a length of 1 whilst having the same direction. I then scaled
    # the normalized vector by 2.
    v.co = 2 * v.co / v.co.magnitude
    
    v.keyframe_insert('co', frame = 120)

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for your answer. Allow me to be even more specific. I have the STL files for a pair of 3d lungs. One is the STL file of the 3D lung during expiration and the other inspiration. I am trying to animate breathing either by morphing between these models with the use of coordinates of vertices on the stl file mesh. I also wish to use python although my knowledge is limited, but I wish to learn. I hope this is clearer. $\endgroup$
    – O I
    Feb 12, 2023 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .