google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

How to use normal map on object created by ShapeFactory #425

Open stewe93 opened 5 years ago

stewe93 commented 5 years ago

Hy Guys! I would really appreciate Your help with this!

So first I created a normal cube with a color material (dont care about await, its for coroutines):

MaterialFactory.makeOpaqueWithColor(context, com.google.ar.sceneform.rendering.Color(color)).await()

then I supplied it to to shape:

ShapeFactory.makeCube(
        Vector3(planeWidth / scaleFactor, planeHeight, planeDepth / scaleFactor),
        Vector3(0.0f, planeHeight / 2, 0.0f),
        blueMaterial // <- here
)

Now I would like to do the same with a custom texture material so changed the material to this:

val wallTexture = Texture.builder()
        .setSource(context, texture_wall) // <- simple png image, x*x size, brick wall 
        .build()
        .await()
MaterialFactory.makeOpaqueWithTexture(context, wallTexture).await()

My question is that if I have the normal map for the applied texture, how can I supply it to the material? I saw the Texture.Usage.Normal parameter but cant figure out how to apply it. My problem is that I cant set the colored texture png and the normalmap of that picture at the same time. Is there a way to achive this? I wouldn't like to make custom shapes and import them, my main purpuse is to build every shape from code!

Bests and thanks in advance

malik-at-work commented 5 years ago

The ShapeFactory is intended for the basic use case and doesn't have a normal map. Similarly the MaterialFactory doesn't expose all the functionality possible yet. For your use case I think the best way to go will be to package up materials in a sfb and use that.

stewe93 commented 5 years ago

Thanks @malik-at-work for Your response. I found a solution: in Unity I made a simple cube with the diffuse and normal map as material on it, exported, then in my code I'm creating a ModelRenderable from it and from the ModelRenderable I can get the material that I want (maybe it's make more sense to use the cube itself instead of just the material of it but my project now build around the ShapeFactory solution). Maybe a better solution would be to use the Material (Sceneform/Rendering lib) class Builder() but 1, I don't know if that can build just the material from an sfb 2, it's private. If this builder can build only the material from the sfb, would You mind to turn this issue to a feature request and make that builder call public?

malik-at-work commented 5 years ago

Yes, we are tracking the request to open up Material at https://github.com/google-ar/sceneform-android-sdk/issues/393 A +1 or me too on that ticket would be great.

stewe93 commented 5 years ago

Done, thanks for your time I'm really appreciate it!