Reputation: 33
screenshot of issue I'm building a very simple app with Sceneform, which at the moment has only one activity with a sceneview, to which I have added a renderable. I want to load a simple model of a planet I've created on blender and exported as an obj file as the renderable. However, the object loads and displays, but has no texture at all or bump mapping, it's just grey. I need to know what is wrong with my code which causes the texture to fail to load. I get no error messages when debugging the app or errors in logcat.
When I use an obj file for a rock that I downloaded on the internet, this works fine, the object is displayed with its textures. However, when I come to use the exact same procedure to import and display a model I created on blender & exported as an obj, I encounter the issue. I've checked for errors in the mtl, sfb and obj file for my model by using the files for the rock which I know work as a reference and despite seemingly having no differences except for the files called and the material settings, I still can't get the texture to show on my model.
I also have added a texture to the renderable directly in the MainActivity.java file by using a completable future texture and the .setTexture() method. (Finally its worth noting I have tried exporting as fbx instead and have the same issue)
MainActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CompletableFuture<Texture> merSurFuture = Texture.builder().setSource(this, R.drawable.mercury_global_map).build();
ModelRenderable.builder().setSource(this, Uri.parse("mercuryobj.sfb") )
.build()
.thenAcceptBoth(merSurFuture, (renderable, texture ) -> {
mObjRenderable = renderable;
mObjRenderable.getMaterial().setTexture("baseColor", texture);
SceneView sceneView = findViewById(R.id.scene_view);
sceneView.setBackgroundColor(Color.BLACK);
Scene scene = sceneView.getScene();
//adding a node to the sceneview
Node node = new Node();
node.setParent(scene);
node.setName("sun");
node.setRenderable(renderable);
node.setLocalPosition(new Vector3(0f,-0.5f,-1f));
})
.exceptionally(throwable -> {
Toast toast = Toast.makeText(this, "unable to load sun", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
mtl file:
`# Blender MTL File: 'Mercury.blend'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 1
map_Bump -bm 0.000030 mercury_topo.png
map_Ks Mercury_global_map.png
map_Kd Mercury_global_map.png
map_Ka Mercury_global_map.png
`
obj file relevant lines:
mtllib mercurymtl.mtl
o Mercury_Sphere
...
usemtl Material.001
s 1
sfb file:
{
materials: [
{
name: 'Material.001',
parameters: [
{
baseColor: 'Mercury_global_map',
},
{
baseColorTint: [
0.80000000000000004,
0.80000000000000004,
0.80000000000000004,
1,
],
},
{
metallic: 0,
},
{
roughness: 1,
},
{
opacity: null,
},
],
source: 'build/sceneform_sdk/default_materials/obj_material.sfm',
},
],
model: {
attributes: [
'Position',
'Orientation',
],
collision: {},
file: 'sampledata/mercuryobj.obj',
name: 'mercuryobj',
recenter: 'root',
scale: 0.20496,
},
samplers: [
{
file: 'sampledata\\Mercury_global_map.png',
name: 'Mercury_global_map',
params: {
usage_type: 'Data',
},
pipeline_name: 'Mercury_global_map.png',
},
],
version: '0.54:2',
}
I expect the model to load and display it's texture, as is the case with the model I downloaded online. The model actually loads completely smooth with no texture at all.
Upvotes: 2
Views: 1623
Reputation: 29
Do it like this:
samplers: [
{
file: 'sampledata/Tex_Beagle.png',
name: 'Tex_Beagle',
pipeline_name: 'Tex_Beagle.png',
injections: [
{usage: "BaseColor",},
],
},
],
And apply 'Tex_Beagle' as baseColor in the parameters of your material :)
Upvotes: 1
Reputation: 1
Remove " \ " this "/" and ctrl+s and try again...
Change like this:
samplers: [
{
file: 'sampledata/Tex_Beagle.png',
name: 'Tex_Beagle',
pipeline_name: 'Tex_Beagle.png',
injections: [
{usage: "Normal",},
],
},
],
Upvotes: 0
Reputation: 3358
A little too late but the documentation states that textures may not be automatically imported into the asset, in this case they should be defined in the sfa file.
In the newly converted sfa file, you can add the texture (an image file) in the samplers
array then in the injections
block declare its usage as Normal
(Adding details to your mesh)
samplers: [
{
file: 'sampledata\\Tex_Beagle.png',
name: 'Tex_Beagle',
pipeline_name: 'Tex_Beagle.png',
injections: [
{usage: "Normal",},
],
},
],
Upvotes: 0