A Content pipeline extension for creating game objects and model at the same time

StackOverflow https://stackoverflow.com/questions/23336805

  •  10-07-2023
  •  | 
  •  

Domanda

I have exported an island.fbx from Blender that I want to import in xna to create an island object:

public class Island
{
   public Vector3[] Slots;
   public Model Model;
}

One mesh inside the fbx is the model of the island. The processor should create a Model instance from it. The other meshes are slots for buildings. The positions of those should just be put in the Slots array:

public override Island Process(NodeContent input, ContentProcessorContext context)
{
    Island newIsland = new Island();

    foreach (NodeContent nc in input.Children)
    {
        string childName = nc.Name.ToLower();
        if (childName.StartsWith("slot"))
            Helpers.ArrayAdd<Vector3>(ref newIsland.Slots, nc.Transform.Translation);
        else if (childName.ToLower().StartsWith("island"))
            newIsland.Model = ???;
    }

    return newIsland;
}

Creating a model instance is the problem.
I guess I could import the fbx twice (or export two fbx files), once for the Model, another time to create the Island object.
But that seems like overkill.

How can I perform both steps in the same processor?

È stato utile?

Soluzione

I'll just do it like this:

public class IslandProcessor : ModelProcessor
{
    public override ModelContent Process(NodeContent input, ContentProcessorContext context)
    {
        ModelContent mc = base.Process(input, context);
        mc.Tag = CreateData(input);

        return mc;
    }
    ...
}

And then load it like this:

Island = new Island();
Island.Model = Content.Load<Model>(@"island");
Island.Data = IslandModel.Tag as IslandData;

Works fine and is not a lot of work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top