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

Unable to inject into multiple materials #712

Closed alexey-pelykh closed 5 years ago

alexey-pelykh commented 5 years ago
Error: Validating Materials: Validating material: Jsonnet Error: [1]: RUNTIME ERROR: duplicate field name: "BaseColor"
     :  third_party/arcore/ar/sceneform/converter/data/sfm_user_module.jsonnet:(11:35)-(14:4)   thunk <texture_name_from_usage>
     :  third_party/arcore/ar/sceneform/converter/data/sfm_user_module.jsonnet:23:38-61 function <anonymous>
     :  fbx_material-1.9.0.sfm:32:23-56 object <anonymous>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:117:33-48    function <canUseOption>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:134:12-27    function <normalizeOptions>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:190:24-55    object <anonymous>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:164:27-40    thunk <param_options>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:165:23-36    
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:165:12-37    function <getUsedOpt>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:202:23-74    object <param_opt_from_name>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:206:23-54    object <param_init_from_name>
     :  third_party/arcore/ar/sceneform/converter/data/mat_helpers.jsonnet:233:26-52    object <anonymous>
     :  std.jsonnet:237:50-62   thunk <array_element>
     :  third_party/arcore/ar/sceneform/converter/data/import_meta_material.jsonnet:(11:19)-(12:45) object <anonymous>
     :  During manifestation

is caused by following:

    "samplers": [
        {
            "file": "textures/dif_silverEdges.jpg",
            "name": "dif_silverEdges",
            "params": {
                "usage_type": "Color"
            },
            "injections": [
                {
                    "usage": "BaseColor"
                }
            ]
        },
        {
            "file": "textures/dif_whiteCanvas.jpg",
            "name": "dif_whiteCanvas",
            "params": {
                "usage_type": "Color"
            },
            "injections": [
                {
                    "usage": "BaseColor"
                }
            ]
        }
  ]

but those are intended for different materials

alexey-pelykh commented 5 years ago

Super-poor documentation:

/// Defines an injection for a new sampler added to an existing source asset.
table SamplerInjectionDef {
  /// If non-empty, limits injections to materials by name
  material_name: string;
  /// The TextureUsage (assigned to our sampler name) which should be injected
  /// into the lull.MaterialTextureDef.
  usage: lull.MaterialTextureUsage;
}

Using material_name solves the issue

aurangzaibumer777 commented 5 years ago

please upload your complete snippet or .sfa file. I'm facing the same problem. I've normal's for each texture

FabienLesueur commented 5 years ago

update please, we need a clear explanation about your solution, cause like you said : SUPER POOR DOCUMENTATION. Need help please!

alexey-pelykh commented 5 years ago

The example above should have been like (note material_name use):

    "samplers": [
        {
            "file": "textures/dif_silverEdges.jpg",
            "name": "dif_silverEdges",
            "params": {
                "usage_type": "Color"
            },
            "injections": [
                {
                    "material_name": "mySilverEdgesMaterial",
                    "usage": "BaseColor"
                }
            ]
        },
        {
            "file": "textures/dif_whiteCanvas.jpg",
            "name": "dif_whiteCanvas",
            "params": {
                "usage_type": "Color"
            },
            "injections": [
                {
                    "material_name": "myWhiteCanvasMaterial",
                    "usage": "BaseColor"
                }
            ]
        }
  ]
FabienLesueur commented 5 years ago

thanks a lot, works like a charm !