iOS transparent area with texture rendered in black (obj, scenekit, model io)











up vote
-1
down vote

favorite












obj file has 2 objects - body and floor.



Floor is a simple clear transparent plane with just 4 vertices.
And I applied both PNG (with transparent area) and JPEG textures, but it all renders in black.
I also tried



transparent.contents = UIImage(named:"floor.png")


I don't know how I can render it properly.
I am using two approaches.




  1. Load obj file via model io then add to scene node.

  2. Load .scn file where the model'd been added beforehand.


But both didn't work out.
The following is the code that I am using now.





  1. With Model I/O



    let scatterFuncFloor = MDLScatteringFunction()
    let floorProperty = MDLMaterialProperty(name: floorTextureFile, semantic: MDLMaterialSemantic.baseColor, url: floorTextureURL)
    let floorMaterial = MDLMaterial(name: NOLOC("FLOOR"), scatteringFunction: scatterFuncFloor)
    floorMaterial.setProperty(floorProperty)
    ............
    for submesh in modelObj.submeshes! {
    if let submesh = submesh as? MDLSubmesh {
    if (index == 0) { // Floor
    submesh.material = floorMaterial
    print(" submesh[0] name:", submesh.name)
    index += 1
    }
    else { // body
    submesh.material = material
    print(" submesh[1] name:", submesh.name)
    }
    }
    }



  2. With .scn file
    (In the preview of scn file, it was rendered properly, but not in the app)



    let url = URL(fileURLWithPath: dir+"/model.scn")
    do {
    let scene = try SCNScene(url: url, options: nil)
    scene.background.contents = UIColor.white
    modelNode = scene.rootNode.childNodes[1]
    //modelNode.childNodes[0].geometry?.materials[0].transparencyMode = SCNTransparencyMode.rgbZero
    self.autoenablesDefaultLighting = true
    self.antialiasingMode = SCNAntialiasingMode.multisampling4X
    self.allowsCameraControl = true
    self.scene = scene
    self.backgroundColor = UIColor.white
    }
    catch {
    print("cannot find or open SCN file")
    }


    Any idea?












share|improve this question
























  • Do you have light?
    – E.Coms
    Nov 7 at 23:59










  • yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
    – yjpark
    Nov 8 at 15:44















up vote
-1
down vote

favorite












obj file has 2 objects - body and floor.



Floor is a simple clear transparent plane with just 4 vertices.
And I applied both PNG (with transparent area) and JPEG textures, but it all renders in black.
I also tried



transparent.contents = UIImage(named:"floor.png")


I don't know how I can render it properly.
I am using two approaches.




  1. Load obj file via model io then add to scene node.

  2. Load .scn file where the model'd been added beforehand.


But both didn't work out.
The following is the code that I am using now.





  1. With Model I/O



    let scatterFuncFloor = MDLScatteringFunction()
    let floorProperty = MDLMaterialProperty(name: floorTextureFile, semantic: MDLMaterialSemantic.baseColor, url: floorTextureURL)
    let floorMaterial = MDLMaterial(name: NOLOC("FLOOR"), scatteringFunction: scatterFuncFloor)
    floorMaterial.setProperty(floorProperty)
    ............
    for submesh in modelObj.submeshes! {
    if let submesh = submesh as? MDLSubmesh {
    if (index == 0) { // Floor
    submesh.material = floorMaterial
    print(" submesh[0] name:", submesh.name)
    index += 1
    }
    else { // body
    submesh.material = material
    print(" submesh[1] name:", submesh.name)
    }
    }
    }



  2. With .scn file
    (In the preview of scn file, it was rendered properly, but not in the app)



    let url = URL(fileURLWithPath: dir+"/model.scn")
    do {
    let scene = try SCNScene(url: url, options: nil)
    scene.background.contents = UIColor.white
    modelNode = scene.rootNode.childNodes[1]
    //modelNode.childNodes[0].geometry?.materials[0].transparencyMode = SCNTransparencyMode.rgbZero
    self.autoenablesDefaultLighting = true
    self.antialiasingMode = SCNAntialiasingMode.multisampling4X
    self.allowsCameraControl = true
    self.scene = scene
    self.backgroundColor = UIColor.white
    }
    catch {
    print("cannot find or open SCN file")
    }


    Any idea?












share|improve this question
























  • Do you have light?
    – E.Coms
    Nov 7 at 23:59










  • yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
    – yjpark
    Nov 8 at 15:44













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











obj file has 2 objects - body and floor.



Floor is a simple clear transparent plane with just 4 vertices.
And I applied both PNG (with transparent area) and JPEG textures, but it all renders in black.
I also tried



transparent.contents = UIImage(named:"floor.png")


I don't know how I can render it properly.
I am using two approaches.




  1. Load obj file via model io then add to scene node.

  2. Load .scn file where the model'd been added beforehand.


But both didn't work out.
The following is the code that I am using now.





  1. With Model I/O



    let scatterFuncFloor = MDLScatteringFunction()
    let floorProperty = MDLMaterialProperty(name: floorTextureFile, semantic: MDLMaterialSemantic.baseColor, url: floorTextureURL)
    let floorMaterial = MDLMaterial(name: NOLOC("FLOOR"), scatteringFunction: scatterFuncFloor)
    floorMaterial.setProperty(floorProperty)
    ............
    for submesh in modelObj.submeshes! {
    if let submesh = submesh as? MDLSubmesh {
    if (index == 0) { // Floor
    submesh.material = floorMaterial
    print(" submesh[0] name:", submesh.name)
    index += 1
    }
    else { // body
    submesh.material = material
    print(" submesh[1] name:", submesh.name)
    }
    }
    }



  2. With .scn file
    (In the preview of scn file, it was rendered properly, but not in the app)



    let url = URL(fileURLWithPath: dir+"/model.scn")
    do {
    let scene = try SCNScene(url: url, options: nil)
    scene.background.contents = UIColor.white
    modelNode = scene.rootNode.childNodes[1]
    //modelNode.childNodes[0].geometry?.materials[0].transparencyMode = SCNTransparencyMode.rgbZero
    self.autoenablesDefaultLighting = true
    self.antialiasingMode = SCNAntialiasingMode.multisampling4X
    self.allowsCameraControl = true
    self.scene = scene
    self.backgroundColor = UIColor.white
    }
    catch {
    print("cannot find or open SCN file")
    }


    Any idea?












share|improve this question















obj file has 2 objects - body and floor.



Floor is a simple clear transparent plane with just 4 vertices.
And I applied both PNG (with transparent area) and JPEG textures, but it all renders in black.
I also tried



transparent.contents = UIImage(named:"floor.png")


I don't know how I can render it properly.
I am using two approaches.




  1. Load obj file via model io then add to scene node.

  2. Load .scn file where the model'd been added beforehand.


But both didn't work out.
The following is the code that I am using now.





  1. With Model I/O



    let scatterFuncFloor = MDLScatteringFunction()
    let floorProperty = MDLMaterialProperty(name: floorTextureFile, semantic: MDLMaterialSemantic.baseColor, url: floorTextureURL)
    let floorMaterial = MDLMaterial(name: NOLOC("FLOOR"), scatteringFunction: scatterFuncFloor)
    floorMaterial.setProperty(floorProperty)
    ............
    for submesh in modelObj.submeshes! {
    if let submesh = submesh as? MDLSubmesh {
    if (index == 0) { // Floor
    submesh.material = floorMaterial
    print(" submesh[0] name:", submesh.name)
    index += 1
    }
    else { // body
    submesh.material = material
    print(" submesh[1] name:", submesh.name)
    }
    }
    }



  2. With .scn file
    (In the preview of scn file, it was rendered properly, but not in the app)



    let url = URL(fileURLWithPath: dir+"/model.scn")
    do {
    let scene = try SCNScene(url: url, options: nil)
    scene.background.contents = UIColor.white
    modelNode = scene.rootNode.childNodes[1]
    //modelNode.childNodes[0].geometry?.materials[0].transparencyMode = SCNTransparencyMode.rgbZero
    self.autoenablesDefaultLighting = true
    self.antialiasingMode = SCNAntialiasingMode.multisampling4X
    self.allowsCameraControl = true
    self.scene = scene
    self.backgroundColor = UIColor.white
    }
    catch {
    print("cannot find or open SCN file")
    }


    Any idea?









ios textures scenekit modelio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 18:52









user6910411

31.9k76692




31.9k76692










asked Nov 7 at 16:30









yjpark

1




1












  • Do you have light?
    – E.Coms
    Nov 7 at 23:59










  • yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
    – yjpark
    Nov 8 at 15:44


















  • Do you have light?
    – E.Coms
    Nov 7 at 23:59










  • yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
    – yjpark
    Nov 8 at 15:44
















Do you have light?
– E.Coms
Nov 7 at 23:59




Do you have light?
– E.Coms
Nov 7 at 23:59












yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
– yjpark
Nov 8 at 15:44




yes. it renders body part fine. but only floor has issue since it is transparent plane and shadow png texture has been mapped and it is rendered in black.
– yjpark
Nov 8 at 15:44

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53193749%2fios-transparent-area-with-texture-rendered-in-black-obj-scenekit-model-io%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53193749%2fios-transparent-area-with-texture-rendered-in-black-obj-scenekit-model-io%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings