-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blend shape operations on ArrayMesh work incorrectly #31595
Comments
For the sake of completeness, that's here: godot/servers/visual_server.cpp Lines 975 to 989 in 791d7f7
|
Full function code if that matters (triangulate_uv just triangulates UVs over vertex distances): func convert_triangles(base: ArrayMesh, helper: ArrayMesh) -> ArrayMesh:
var v2idxb = {}
var v2idxh = {}
var v2uv = {}
var sc = 0
var ret_mesh: = ArrayMesh.new()
var base_surf_array = base.surface_get_arrays(sc)
for idx in range(base_surf_array[ArrayMesh.ARRAY_VERTEX].size()):
var v = base_surf_array[ArrayMesh.ARRAY_VERTEX][idx]
v2idxb[v] = idx
var helper_surf_array = helper.surface_get_arrays(sc)
var bshapes = helper.surface_get_blend_shape_arrays(sc)
for idx in range(helper_surf_array[ArrayMesh.ARRAY_VERTEX].size()):
var v = helper_surf_array[ArrayMesh.ARRAY_VERTEX][idx]
v2idxh[v] = idx
# find 3 closest vertices on base mesh
for k in v2idxh.keys():
var res = []
var ds = []
for l in v2idxb.keys():
if res.size() < 3:
res.push_back(l)
ds.push_back(k.distance_to(l))
else:
var idx = -1
for m in range(ds.size()):
if idx < 0:
idx = m
elif ds[idx] < ds[m]:
idx = m
var d = k.distance_to(l)
if d < ds[idx]:
res[idx] = l
ds[idx] = d
var vs = PoolVector3Array(res)
var uvs = PoolVector2Array()
for p in res:
var idx = v2idxb[p]
var uvb = base_surf_array[ArrayMesh.ARRAY_TEX_UV][idx]
uvs.push_back(uvb)
var uvh = triangulate_uv(k, vs, uvs)
helper_surf_array[ArrayMesh.ARRAY_TEX_UV][v2idxh[k]] = uvh
for h in bshapes.size():
bshapes[h][ArrayMesh.ARRAY_TEX_UV][v2idxh[k]] = uvh
for k in range(helper.get_blend_shape_count()):
ret_mesh.add_blend_shape(helper.get_blend_shape_name(k))
ret_mesh.blend_shape_mode
ret_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, helper_surf_array, bshapes)
return ret_mesh |
I just did not want pople to be frighened by larger portions of code, as bugs like that will hang forever, but still would add that for completeness. |
@slapin Yeah I just added the link to the relevant file and lines so that interested contributors can browse the code freely, without having to grep for it to find the relevant file and line again. |
@akien-mga thanks, my github-fu is not advanced to this extent. |
It's a bit offtopic, but just FYI as it's a convenient feature: you can browse to a file through GitHub's web UI, select lines by Shift+clicking on line numbers on the left side, and there's a "..." options menu with "Copy permalink" which gives you a link to those lines at the current HEAD commit: And when you paste it in an issue/PR, GitHub automatically converts it to the widget seen above with the code. |
Thanks a lot, that is very useful to know.
…On Fri, Aug 23, 2019 at 1:55 PM Rémi Verschelde ***@***.***> wrote:
It's a bit offtopic, but just FYI as it's a convenient feature: you can
browse to a file through GitHub's web UI, select lines by Shift+clicking on
line numbers on the left side, and there's a "..." options menu with "Copy
permalink" which gives you a link to those lines at the current HEAD
commit:
https://github.com/godotengine/godot/blob/791d7f78b52f5b828aa5541897e12c6a1861ef6f/servers/visual_server.cpp#L975-L989
[image: Screenshot_20190823_125259]
<https://user-images.githubusercontent.com/4701338/63587797-2276d680-c5a5-11e9-8462-1b5b5391f617.png>
And when you paste it in an issue/PR, GitHub automatically converts it to
the widget seen above with the code.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#31595?email_source=notifications&email_token=AAABPUZGT64NRKO7KX7SX4DQF663FA5CNFSM4IO6ELC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD473XBY#issuecomment-524270471>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAABPU3BJNEBURRFPL4NYSTQF663FANCNFSM4IO6ELCQ>
.
|
can both of you have a look at this finding to see if this explain why ArrayMesh is not able to set blendshape in Csharp ================================================= In Csharp, BlendShape are get and set through two classes Interestingly, in ArrayMesh.cs there is no corresponding SetBlendShapeWeight method ================================================ /// <summary>
/// <para>Sets the weight for a given blend shape associated with this instance.</para>
/// </summary>
[GodotMethod("instance_set_blend_shape_weight")]
public static void InstanceSetBlendShapeWeight(RID instance, int shape, float weight)
{
NativeCalls.godot_icall_3_630(method_bind_262, ptr, RID.GetPtr(instance), shape, ref weight);
} |
Can anyone still reproduce this bug in Godot 3.2.3 or any later release? If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop. |
Still present on Godot 4.0.dev 9ca0d66 Here's the code I used to workaround the problem var prim: int = mesh.surface_get_primitive_type(surf_idx)
var fmt_compress_flags: int = mesh.surface_get_format(surf_idx)
var arr: Array = mesh.surface_get_arrays(surf_idx)
var bsarr: Array = mesh.surface_get_blend_shape_arrays(surf_idx)
var lods: Dictionary = {} # mesh.surface_get_lods(surf_idx) isn't exposed :'-(
# surface_get_blend_shape_arrays seems to truncate each result at 7 elements or so. Let's add them back.
for bsidx in range(len(bsarr)):
bsarr[bsidx].resize(len(arr))
for i in range(len(arr)):
if i >= ArrayMesh.ARRAY_INDEX or typeof(arr[i]) == TYPE_NIL:
bsarr[bsidx][i] = null
elif typeof(bsarr[bsidx][i]) == TYPE_NIL or len(bsarr[bsidx][i]) == 0:
bsarr[bsidx][i] = arr[i].duplicate()
bsarr[bsidx][i].resize(0)
bsarr[bsidx][i].resize(len(arr[i]))
... PERFORM VERTEX MODIFICATIONS HERE ...
mesh.add_surface_from_arrays(prim, arr, bsarr, lods, fmt_compress_flags) Godot isn't the happiest about this: it prints this error when I add arrays... but the above code does seem to workaround the bug. ERROR: Storage buffer supplied (binding: 2) is invalid. |
#54062 is at least tangentially related. If the solution I propose to fix it is implemented it would heavily effect this code. I am recommending blend shapes be inside the mesh resource for reasons given in this post and inside the project I made in the most recent comment. |
Is this this reproducible in latest 4.0 builds? |
I think this is fixed in Godot 4, I can not reproduce the issue in recent master with a valid BlendShape Array. A BlendShape array requires format Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK. This means only array index Mesh::ARRAY_VERTEX + Mesh::ARRAY_NORMAL + Mesh::ARRAY_TANGENT are allowed for BlendShape arrays. The script example code was adding other mesh arrays as well hence why it printend errors. |
Closing per @smix8's comment. |
Code below (on git master)
generates a lot of errors for simple gdscript:
which prevents any reasonable manipulation with meshes with blend shapes. Any ideas on fixing this? This used to work fine a few months ago. Original mesh is imported from Blender-2.80 release using godot-blender-exporter aka .escn exporter and works perfectly fine.
The text was updated successfully, but these errors were encountered: