Search code examples
c#urhosharp

No image texture on StaticModel


I have a very simply scene (camera, light set up as usual). I want to apply a simple image material over the model. If I use one of the convenience models like Sphere, the object renders with the material all right:

  var model = modelNode.CreateComponent<Sphere>();
  model.SetMaterial(Material.FromImage("Textures/small.jpg"));

If I switch to a static model (it's the default cube from Blender), nothing renders (or probably, it renders invisible). With a color material, it works all right, so there is no question about the model itself.

  var model = modelNode.CreateComponent<StaticModel>();
  model.Model = ResourceCache.GetModel("Models/Cube.mdl", false);
  //model.SetMaterial(CoreAssets.Materials.DefaultGrey);
  //model.SetMaterial(Material.FromColor(Color.Yellow));
  model.SetMaterial(Material.FromImage("Textures/small.jpg"));

For reference, the rest of the scene is:

  scene = new Scene();
  octree = scene.CreateComponent<Octree>();

  var cameraNode = scene.CreateChild();
  cameraNode.Position = new Vector3(0, 0, -10);
  cameraNode.SetDirection(new Vector3(0, 0, 0));
  camera = cameraNode.CreateComponent<Camera>();

  var lightNode = cameraNode.CreateChild();
  lightNode.Position = new Vector3(5, 5, -5);
  lightNode.SetDirection(new Vector3(0, 0, 0));

  var light = lightNode.CreateComponent<Light>();
  light.LightType = LightType.Directional;
  light.Brightness = 1.5f;
  light.CastShadows = true;
  light.Color = Color.White;
  light.Range = 10;

Solution

  • Well, the model didn't have all the necessary details exported...