public void CreateExampleBone(Character character) { // Generate a simple cubic spline that will act as the radius of a long bone: SortedList <float, float> radiusPoints = new SortedList <float, float>(); radiusPoints.Add(0.0f, 0.7f * 0.92f); radiusPoints.Add(0.02f, 0.7f * 0.92f); radiusPoints.Add(0.15f, 0.7f * 0.8f); radiusPoints.Add(0.5f, 0.7f * 0.7f); radiusPoints.Add(0.8f, 0.7f * 0.76f); radiusPoints.Add(0.98f, 0.7f * 0.8f); radiusPoints.Add(1.0f, 0.7f * 0.8f); CubicSpline1D boneRadius = new CubicSpline1D(radiusPoints); // Define the center curve of the long bone: SortedList <float, Numerics.Vector3> centerPoints = new SortedList <float, Numerics.Vector3>(); centerPoints.Add(0.0f, new Numerics.Vector3(0.0f, 0.0f, 2.7f)); centerPoints.Add(0.25f, new Numerics.Vector3(-0.3f, -0.5f, 1.0f)); centerPoints.Add(0.5f, new Numerics.Vector3(0.3f, 1.0f, 0.0f)); centerPoints.Add(0.75f, new Numerics.Vector3(0.8f, 1.0f, -1.0f)); centerPoints.Add(1.0f, new Numerics.Vector3(0.6f, -0.5f, -0.9f)); SpatialCubicSpline boneCenter = new SpatialCubicSpline(centerPoints); //Line centerLine = new Line(new Numerics.Vector3(0.0f, 0.0f, 1.7f), // new Numerics.Vector3(0f, 0.0f, -1.7f)); // Add a long bone to the character: character.bones.Add(new Anatomy.Bones.LongBone(boneCenter, boneRadius)); // Generate the geometry vertices of the first bone with resolution U=32 and resolution V=32: UVMesh mesh = character.bones[0].GetGeometry().GenerateMesh(64, 1024); // Finally upload the mesh to Godot: MeshInstance newMesh = new MeshInstance(); newMesh.Mesh = new GodotMeshConverter(mesh); newMesh.SetSurfaceMaterial(0, (Material)GD.Load("res://gui/BoneMaterial.tres")); AddChild(newMesh); }
public void CreateExampleBones(Anatomy.Skeleton skeleton) { // Generate a simple cubic spline that will act as the radius of a long bone: SortedList <double, double> radiusPoints = new SortedList <double, double>(); radiusPoints.Add(-3.5f, 0.7f * 1.2f); radiusPoints.Add(-1.0f, 0.7f * 1.2f); radiusPoints.Add(0.02f, 0.7f * 1.2f); radiusPoints.Add(0.15f, 0.7f * 1.0f); radiusPoints.Add(0.5f, 0.7f * 0.7f); radiusPoints.Add(0.8f, 0.7f * 0.76f); radiusPoints.Add(0.98f, 0.7f * 0.8f); radiusPoints.Add(4.5f, 0.7f * 0.8f); LinearSpline1D boneRadius = new LinearSpline1D(radiusPoints); // Define the center curve of the long bone: SortedList <double, dvec3> centerPoints = new SortedList <double, dvec3>(); centerPoints.Add(0.0f, new dvec3(0.0f, 0.0f, 2.7f)); centerPoints.Add(0.25f, new dvec3(-0.3f, -0.5f, 1.0f)); centerPoints.Add(0.5f, new dvec3(0.3f, 1.0f, 0.0f)); centerPoints.Add(0.75f, new dvec3(0.8f, 1.0f, -1.0f)); centerPoints.Add(1.0f, new dvec3(0.6f, -0.5f, -0.9f)); SpatialCubicSpline boneCenter = new SpatialCubicSpline(centerPoints); // Add first bone: LineSegment centerLine = new LineSegment(new dvec3(0.0f, 0.0f, 0.5f), new dvec3(0.001f, 10.0f, 0.51f)); var bone1 = new Anatomy.Bones.LongBone(centerLine, boneRadius); var jointInteraction = new Anatomy.Bone.JointDeformation(skeleton.joints[0], RayCastDirection.Outwards, 3.0f); bone1.InteractingJoints.Add(jointInteraction); skeleton.bones.Add(bone1); // Add second bone: //LineSegment centerLine2 = new LineSegment(new dvec3(0.0f, -10.0f, 0.5f), // new dvec3(0.001f, -1.0f, 0.51f)); //var bone2 = new Anatomy.Bones.LongBone(centerLine2, 1.1f); //bone2.InteractingJoints.Add((skeleton.joints[0], RayCastDirection.Outwards, 3.0f)); //skeleton.bones.Add(bone2); // Generate the geometry vertices of the first bone with resolution U=128 and resolution V=128: foreach (var bone in skeleton.bones) { #if GODOT_HTML5 UVMesh mesh = bone.GetGeometry().GenerateMesh(32, 32); #else UVMesh mesh = bone.GetGeometry().GenerateMesh(256, 256); #endif // Finally upload the mesh to Godot: MeshInstance newMesh = new MeshInstance(); newMesh.Mesh = new GodotMeshConverter(mesh); // Give each mesh a random color: var boneMaterial = (SpatialMaterial)GD.Load("res://BoneMaterial.tres").Duplicate(); boneMaterial.AlbedoColor = new Color(GD.Randf(), GD.Randf(), GD.Randf(), GD.Randf()); newMesh.SetSurfaceMaterial(0, boneMaterial); AddChild(newMesh); } }