Skip to main content
Last edit was great, but partly just duplicated content from comments about the solution into the question body. Comments belong in comments, and solutions in solutions. Removed redundant text.
Source Link

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

Solved. In an nutshell, every design-time NodeContent instance gets a unique ModelBone at run-time. Details to come.

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

Solved. In an nutshell, every design-time NodeContent instance gets a unique ModelBone at run-time. Details to come.

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Tweeted twitter.com/StackGameDev/status/1534777316051668993
added markdown to code in text, moved answer from comments in question post to preserve it, 2 broken links fixed, cf. https://meta.stackoverflow.com/a/406565/4751173
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

I'm trying to manually create a ModelContentModelContent instance that includes custom Bone data in a custom ContentProcessorContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContentModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContentModelContent is created, it's not possible to add bones because the BonesBones collection is read-only. And it seems the only way to create the ModelContentModelContent instance is to call the standard ModelProcessorModelProcessor via ContentProcessorContext.ConvertContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContentBoneContent class has a constructor but no methods except those inherited from NodeContentNodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContentNodeContent with two children: one MeshContentMeshContent and one BoneContentBoneContent as the root of my skeleton; then pass the root NodeContentNodeContent to ContentProcessorContext.ConvertContentProcessorContext.Convert?

Off to try that now...

Solved. In an nutshell, every design-time NodeContent instance gets a unique ModelBone at run-time. Details to come.

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

Solved. In an nutshell, every design-time NodeContent instance gets a unique ModelBone at run-time. Details to come.

2 broken links fixed, cf. https://meta.stackoverflow.com/a/406565/4751173
Source Link

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRuneDigitalRune and Sean Hargreaves blogSean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

I'm trying to manually create a ModelContent instance that includes custom Bone data in a custom ContentProcessor in the XNA Content Pipeline. I can't seem to create or assign manually created bone data due to either private constructors or read-only collections (at every turn).

The code I have right now that creates a single triangle ModelContent that I'd like to create a bone for is:

MeshContent mc = new MeshContent();
mc.Positions.Add(new Vector3(-10, 0, 0));
mc.Positions.Add(new Vector3(0, 10, 0));
mc.Positions.Add(new Vector3(10, 0, 0));

GeometryContent gc = new GeometryContent();
gc.Indices.AddRange(new int[] { 0, 1, 2 });
gc.Vertices.AddRange(new int[] { 0, 1, 2 });
mc.Geometry.Add(gc);

// Create normals
MeshHelper.CalculateNormals(mc, true);

// finally, convert it to a model
ModelContent model = context.Convert<MeshContent, ModelContent>(mc, "ModelProcessor");

The documentation on XNA is amazingly sparse. I've been referencing the class diagrams created by DigitalRune and Sean Hargreaves blog, but I haven't found anything on creating bone content.

Once the ModelContent is created, it's not possible to add bones because the Bones collection is read-only. And it seems the only way to create the ModelContent instance is to call the standard ModelProcessor via ContentProcessorContext.Convert. So it's a bit of a catch-22.

The BoneContent class has a constructor but no methods except those inherited from NodeContent... though now (true to form) maybe I've realized the solution by asking the question. Should I create a root NodeContent with two children: one MeshContent and one BoneContent as the root of my skeleton; then pass the root NodeContent to ContentProcessorContext.Convert?

Off to try that now...

Source Link
Loading