Issues with creating SkinnedModel procedurally

Since it is possible to create procedural models (at least for static models), it seems reasonable that similar approach should work for creating skinned models


Issue #1:

Using _skinnedMesh.UpdateMesh(…) will crash Flax Editor and built game with Assertion Failed


[ 00:02:41.533 ]: [Error] Assertion failed!
File: C:\Flax\FlaxEngine\Source\Engine\Graphics\Models\SkinnedMesh.cpp
Line: 76

Expression: positionStream.IsLinear(PixelFormat::R32G32B32_Float) 
================================================================
[ 00:02:41.533 ]: [Error] Critical error! Reason: Assertion failed!
File: C:\Flax\FlaxEngine\Source\Engine\Graphics\Models\SkinnedMesh.cpp
Line: 76

Expression: positionStream.IsLinear(PixelFormat::R32G32B32_Float) 
[ 00:02:41.620 ]: [Error] Stack trace:
[ 00:02:41.620 ]: [Error]     at FlaxEditor.exe!PlatformBase::Assert() in C:\Flax\FlaxEngine\Source\Engine\Platform\Base\PlatformBase.cpp:line 573
[ 00:02:41.620 ]: [Error]     at FlaxEditor.exe!`anonymous namespace'::UpdateMesh() in C:\Flax\FlaxEngine\Source\Engine\Graphics\Models\SkinnedMesh.cpp:line 76
[ 00:02:41.620 ]: [Error]     at FlaxEditor.exe!SkinnedMesh::UpdateMeshUInt() in C:\Flax\FlaxEngine\Source\Engine\Graphics\Models\SkinnedMesh.cpp:line 415
[ 00:02:41.620 ]: [Error]     at FlaxEditor.exe!SkinnedMeshInternal::UpdateMeshUInt() in C:\Flax\FlaxEngine\Cache\Intermediate\FlaxEditor\Windows\x64\Development\Graphics\Graphics.Bindings.Gen.cpp:line 5203
[ 00:02:41.620 ]: [Error]     at 0x7ffcbc6cad17

Is the code below using the right approach? Or should something be done differently?

public override void OnStart()
{
	Float3[] vertices = new[]
	{
		new Float3(0.1f, 0.1f, 0.1f),
		new Float3(2.1f, 0.1f, 0.1f),
		new Float3(0.1f, 1.1f, 0.1f),
		new Float3(1.1f, 1.1f, 0.1f)
	};

	uint[] indecies = new uint[]
	{
		//front face
		0, 1, 2,
		2, 1, 3
	};

	Color[] colors = new Color[]
	{
		new Color(222,0,0,0),
		new Color(0,222,0,0),
		new Color(222,0,222,0),
		new Color(222,222,1,0)
	};

	Int4[] blendIndices = new Int4[vertices.Length];

	Float4[] blendWeights = new Float4[vertices.Length];
	blendWeights = new Float4[]
		{
				new Float4(1,0,0,0),
				new Float4(1,0,0,0),
				new Float4(1,0,0,0),
				new Float4(1,0,0,0)
		}
;

	SkinnedModel _skinnedModel = Content.CreateVirtualAsset<SkinnedModel>();
	_skinnedModel.SetupLODs(new[] { 1 });
	_skinnedModel.LODs[0].Meshes[0].UpdateMesh(vertices, indecies, blendIndices, blendWeights);

Issue #2:

MeshAccessor allows to set Positions, Indecies, Normals, Tangents, Colors … but can only get BlendIndecies and BlendWeights. Would be nice to be able to set those also.

Thanks for reporting this! Fixed in Fix procedural Skinned Mesh creation from code · FlaxEngine/FlaxEngine@593b989 · GitHub (master branch)

Thank you for the quick fix! :+1:

Perhaps a noob-ish question. When/How can the updated Flax Engine with the fix be used?
By downloading the “master branch” through the Flax Launcher?
Did that, but got the same error … so perhaps need to wait for that to be updated?
Or by using git to download the updated master branch and compiling the project with Visual Studio?

[UPDATE] The Getting Started webpage does mention downloading the “master branch (daily)” with the Flax Launcher. So, likely it’s just a matter of time for that to be updated?

Yes, those builds are created automatically every day at night (7:30 AM GMT+2) and can be downloaded manually from Continuous Deployment · Workflow runs · FlaxEngine/FlaxEngine · GitHub or via Launcher. They are not made when we don’t have any changes on master tho.