Can't feed a MDLMesh container with 3D model as SCNGeometry
I'm creating AR app (Xcode 10.1, Swift 4.2.1).
I'd like to load USDZ
3D object into an empty SceneKit's scene and then process it as MDL
mesh.
Here's my code:
import ARKit
import SceneKit.ModelIO
let scene = SCNScene(named: "art.scnassets/emptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let refNode = SCNReferenceNode(url: refURL)
refNode?.load()
scene.rootNode.addChildNode(refNode!)
let helicopterGeo = refNode!.geometry
let mdlMesh = MDLMesh(scnGeometry: helicopterGeo!) // ERROR APPEARS HERE
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
But compiler gives me an error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
The question is: what approach should I use to assign a "Helicopter.usdz"
geometry to a helicopterGeo
constant?
Help me find a workaround, please!
You can download USDZ
file for testing HERE.
swift scenekit arkit ios12 modelio
add a comment |
I'm creating AR app (Xcode 10.1, Swift 4.2.1).
I'd like to load USDZ
3D object into an empty SceneKit's scene and then process it as MDL
mesh.
Here's my code:
import ARKit
import SceneKit.ModelIO
let scene = SCNScene(named: "art.scnassets/emptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let refNode = SCNReferenceNode(url: refURL)
refNode?.load()
scene.rootNode.addChildNode(refNode!)
let helicopterGeo = refNode!.geometry
let mdlMesh = MDLMesh(scnGeometry: helicopterGeo!) // ERROR APPEARS HERE
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
But compiler gives me an error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
The question is: what approach should I use to assign a "Helicopter.usdz"
geometry to a helicopterGeo
constant?
Help me find a workaround, please!
You can download USDZ
file for testing HERE.
swift scenekit arkit ios12 modelio
Have you triedlet helicopterGeo = refNode!.geometry
?
– Steve O'Connor
Oct 17 '18 at 9:23
add a comment |
I'm creating AR app (Xcode 10.1, Swift 4.2.1).
I'd like to load USDZ
3D object into an empty SceneKit's scene and then process it as MDL
mesh.
Here's my code:
import ARKit
import SceneKit.ModelIO
let scene = SCNScene(named: "art.scnassets/emptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let refNode = SCNReferenceNode(url: refURL)
refNode?.load()
scene.rootNode.addChildNode(refNode!)
let helicopterGeo = refNode!.geometry
let mdlMesh = MDLMesh(scnGeometry: helicopterGeo!) // ERROR APPEARS HERE
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
But compiler gives me an error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
The question is: what approach should I use to assign a "Helicopter.usdz"
geometry to a helicopterGeo
constant?
Help me find a workaround, please!
You can download USDZ
file for testing HERE.
swift scenekit arkit ios12 modelio
I'm creating AR app (Xcode 10.1, Swift 4.2.1).
I'd like to load USDZ
3D object into an empty SceneKit's scene and then process it as MDL
mesh.
Here's my code:
import ARKit
import SceneKit.ModelIO
let scene = SCNScene(named: "art.scnassets/emptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let refNode = SCNReferenceNode(url: refURL)
refNode?.load()
scene.rootNode.addChildNode(refNode!)
let helicopterGeo = refNode!.geometry
let mdlMesh = MDLMesh(scnGeometry: helicopterGeo!) // ERROR APPEARS HERE
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
But compiler gives me an error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
The question is: what approach should I use to assign a "Helicopter.usdz"
geometry to a helicopterGeo
constant?
Help me find a workaround, please!
You can download USDZ
file for testing HERE.
swift scenekit arkit ios12 modelio
swift scenekit arkit ios12 modelio
edited Nov 15 '18 at 20:40
ARGeo
asked Oct 14 '18 at 21:43
ARGeoARGeo
5,59952753
5,59952753
Have you triedlet helicopterGeo = refNode!.geometry
?
– Steve O'Connor
Oct 17 '18 at 9:23
add a comment |
Have you triedlet helicopterGeo = refNode!.geometry
?
– Steve O'Connor
Oct 17 '18 at 9:23
Have you tried
let helicopterGeo = refNode!.geometry
?– Steve O'Connor
Oct 17 '18 at 9:23
Have you tried
let helicopterGeo = refNode!.geometry
?– Steve O'Connor
Oct 17 '18 at 9:23
add a comment |
3 Answers
3
active
oldest
votes
This should work:
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
SCNReferenceNode
only works for .scn files. You can then get the geometry from a child node of the rootNode
of the scene
.
let helicopterNode = scene.rootNode.childNode(withName: "helicopter", recursively: true)
let geometry = helicopterNode.geometry!
Edit
Using one of the files from the AR Quick Look Gallery I managed to get this code to work. The main problem that I had was with the name of the specific child node, there was one called "RetroTV" but it did not have any geometry attached to it, it was just the parent for both "RetroTVBody" and "RetroTVScreen." The only problem is that it isn't loading the textures for the geometry.
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "retrotv",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let tvNode = scene.rootNode.childNode(withName: "RetroTVBody", recursively: true)
let geometry = tvNode!.geometry!
else
print("invalid path!")
The above code also works with the tvNode
and geometry
declarations outside of the if let
statement.
@argeo It is possible thathelicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?
– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrappinghelicopterNode
and see if anything changes
– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of yourif let
being called, I tested it and that is the problem I had.
– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in thewithName
argument ofscene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing outscene.rootNode.childNodes
to see if it is actually working.
– Brandon
Nov 15 '18 at 23:17
|
show 1 more comment
I don't have an exact answer, but what I would do in your situation would be to examine the hierarchy of refNode
.
Place a breakpoint after it's loaded and use the debugger to see if it's got any children. Do those children have any geometries? Do they have any children with geometry?
When creating 3D assets, sometimes multiple sections will be grouped on a parent node, and in many cases that parent node is empty.
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball'sshape
node connected to itstransform
node). Result is the same: error.
– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
add a comment |
Was it an error in Maya binary file, or an error of usdz
conversion – I don't know exactly. Xcode didn't see a correct name of the object in the simplest hierarchy of a Scene graph
: Instead of pHelicopter1
it just showed Helicopter
. My 3D object was made from pCube1
using polygonal Extrude
tool.
Here's the final code and it works fine:
import ARKit
import SceneKit.ModelIO
//..........................................................
var scene = SCNScene(named: "art.scnassets/EmptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let helicopterNode = scene.rootNode.childNode(withName: "pHelicopter1",
recursively: true)
let geometry = helicopterNode!.geometry!
let mdlMesh = MDLMesh(scnGeometry: geometry)
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
else
print("Invalid path!")
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52807356%2fcant-feed-a-mdlmesh-container-with-3d-model-as-scngeometry%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This should work:
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
SCNReferenceNode
only works for .scn files. You can then get the geometry from a child node of the rootNode
of the scene
.
let helicopterNode = scene.rootNode.childNode(withName: "helicopter", recursively: true)
let geometry = helicopterNode.geometry!
Edit
Using one of the files from the AR Quick Look Gallery I managed to get this code to work. The main problem that I had was with the name of the specific child node, there was one called "RetroTV" but it did not have any geometry attached to it, it was just the parent for both "RetroTVBody" and "RetroTVScreen." The only problem is that it isn't loading the textures for the geometry.
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "retrotv",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let tvNode = scene.rootNode.childNode(withName: "RetroTVBody", recursively: true)
let geometry = tvNode!.geometry!
else
print("invalid path!")
The above code also works with the tvNode
and geometry
declarations outside of the if let
statement.
@argeo It is possible thathelicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?
– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrappinghelicopterNode
and see if anything changes
– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of yourif let
being called, I tested it and that is the problem I had.
– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in thewithName
argument ofscene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing outscene.rootNode.childNodes
to see if it is actually working.
– Brandon
Nov 15 '18 at 23:17
|
show 1 more comment
This should work:
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
SCNReferenceNode
only works for .scn files. You can then get the geometry from a child node of the rootNode
of the scene
.
let helicopterNode = scene.rootNode.childNode(withName: "helicopter", recursively: true)
let geometry = helicopterNode.geometry!
Edit
Using one of the files from the AR Quick Look Gallery I managed to get this code to work. The main problem that I had was with the name of the specific child node, there was one called "RetroTV" but it did not have any geometry attached to it, it was just the parent for both "RetroTVBody" and "RetroTVScreen." The only problem is that it isn't loading the textures for the geometry.
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "retrotv",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let tvNode = scene.rootNode.childNode(withName: "RetroTVBody", recursively: true)
let geometry = tvNode!.geometry!
else
print("invalid path!")
The above code also works with the tvNode
and geometry
declarations outside of the if let
statement.
@argeo It is possible thathelicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?
– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrappinghelicopterNode
and see if anything changes
– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of yourif let
being called, I tested it and that is the problem I had.
– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in thewithName
argument ofscene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing outscene.rootNode.childNodes
to see if it is actually working.
– Brandon
Nov 15 '18 at 23:17
|
show 1 more comment
This should work:
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
SCNReferenceNode
only works for .scn files. You can then get the geometry from a child node of the rootNode
of the scene
.
let helicopterNode = scene.rootNode.childNode(withName: "helicopter", recursively: true)
let geometry = helicopterNode.geometry!
Edit
Using one of the files from the AR Quick Look Gallery I managed to get this code to work. The main problem that I had was with the name of the specific child node, there was one called "RetroTV" but it did not have any geometry attached to it, it was just the parent for both "RetroTVBody" and "RetroTVScreen." The only problem is that it isn't loading the textures for the geometry.
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "retrotv",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let tvNode = scene.rootNode.childNode(withName: "RetroTVBody", recursively: true)
let geometry = tvNode!.geometry!
else
print("invalid path!")
The above code also works with the tvNode
and geometry
declarations outside of the if let
statement.
This should work:
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
SCNReferenceNode
only works for .scn files. You can then get the geometry from a child node of the rootNode
of the scene
.
let helicopterNode = scene.rootNode.childNode(withName: "helicopter", recursively: true)
let geometry = helicopterNode.geometry!
Edit
Using one of the files from the AR Quick Look Gallery I managed to get this code to work. The main problem that I had was with the name of the specific child node, there was one called "RetroTV" but it did not have any geometry attached to it, it was just the parent for both "RetroTVBody" and "RetroTVScreen." The only problem is that it isn't loading the textures for the geometry.
var scene: SCNScene!
if let filePath = Bundle.main.path(forResource: "retrotv",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let tvNode = scene.rootNode.childNode(withName: "RetroTVBody", recursively: true)
let geometry = tvNode!.geometry!
else
print("invalid path!")
The above code also works with the tvNode
and geometry
declarations outside of the if let
statement.
edited Nov 15 '18 at 22:46
answered Nov 15 '18 at 18:20
BrandonBrandon
1818
1818
@argeo It is possible thathelicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?
– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrappinghelicopterNode
and see if anything changes
– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of yourif let
being called, I tested it and that is the problem I had.
– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in thewithName
argument ofscene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing outscene.rootNode.childNodes
to see if it is actually working.
– Brandon
Nov 15 '18 at 23:17
|
show 1 more comment
@argeo It is possible thathelicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?
– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrappinghelicopterNode
and see if anything changes
– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of yourif let
being called, I tested it and that is the problem I had.
– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in thewithName
argument ofscene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing outscene.rootNode.childNodes
to see if it is actually working.
– Brandon
Nov 15 '18 at 23:17
@argeo It is possible that
helicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?– Brandon
Nov 15 '18 at 19:48
@argeo It is possible that
helicopterNode
is nil, do you know the actual name of the helicopter geometry in the udsz file?– Brandon
Nov 15 '18 at 19:48
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrapping
helicopterNode
and see if anything changes– Brandon
Nov 15 '18 at 19:56
@argeo I don't have a usdz file to test with, but is it a run time or a compile time error, try force unwrapping
helicopterNode
and see if anything changes– Brandon
Nov 15 '18 at 19:56
@argeo Is the code inside of your
if let
being called, I tested it and that is the problem I had.– Brandon
Nov 15 '18 at 20:18
@argeo Is the code inside of your
if let
being called, I tested it and that is the problem I had.– Brandon
Nov 15 '18 at 20:18
@ARGeo It seems that the issue is in the
withName
argument of scene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo It seems that the issue is in the
withName
argument of scene.rootNode.childNode
– Brandon
Nov 15 '18 at 22:53
@ARGeo try printing out
scene.rootNode.childNodes
to see if it is actually working.– Brandon
Nov 15 '18 at 23:17
@ARGeo try printing out
scene.rootNode.childNodes
to see if it is actually working.– Brandon
Nov 15 '18 at 23:17
|
show 1 more comment
I don't have an exact answer, but what I would do in your situation would be to examine the hierarchy of refNode
.
Place a breakpoint after it's loaded and use the debugger to see if it's got any children. Do those children have any geometries? Do they have any children with geometry?
When creating 3D assets, sometimes multiple sections will be grouped on a parent node, and in many cases that parent node is empty.
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball'sshape
node connected to itstransform
node). Result is the same: error.
– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
add a comment |
I don't have an exact answer, but what I would do in your situation would be to examine the hierarchy of refNode
.
Place a breakpoint after it's loaded and use the debugger to see if it's got any children. Do those children have any geometries? Do they have any children with geometry?
When creating 3D assets, sometimes multiple sections will be grouped on a parent node, and in many cases that parent node is empty.
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball'sshape
node connected to itstransform
node). Result is the same: error.
– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
add a comment |
I don't have an exact answer, but what I would do in your situation would be to examine the hierarchy of refNode
.
Place a breakpoint after it's loaded and use the debugger to see if it's got any children. Do those children have any geometries? Do they have any children with geometry?
When creating 3D assets, sometimes multiple sections will be grouped on a parent node, and in many cases that parent node is empty.
I don't have an exact answer, but what I would do in your situation would be to examine the hierarchy of refNode
.
Place a breakpoint after it's loaded and use the debugger to see if it's got any children. Do those children have any geometries? Do they have any children with geometry?
When creating 3D assets, sometimes multiple sections will be grouped on a parent node, and in many cases that parent node is empty.
answered Nov 15 '18 at 20:28
EmilioPelaezEmilioPelaez
9,30932436
9,30932436
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball'sshape
node connected to itstransform
node). Result is the same: error.
– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
add a comment |
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball'sshape
node connected to itstransform
node). Result is the same: error.
– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
There's no geometry at all except this one. And my scene is empty. Breakpoint says nothing useful...
– ARGeo
Nov 15 '18 at 20:29
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
Did you use the console to examine the children and see if they have any geometry?
– EmilioPelaez
Nov 16 '18 at 3:04
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball's
shape
node connected to its transform
node). Result is the same: error.– ARGeo
Nov 16 '18 at 8:19
I also tested a simple sphere made in Maya. There were no hierarchy at all (no groups, just Maya ball's
shape
node connected to its transform
node). Result is the same: error.– ARGeo
Nov 16 '18 at 8:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
Thanks for your answer, Emilio!
– ARGeo
Nov 16 '18 at 12:19
add a comment |
Was it an error in Maya binary file, or an error of usdz
conversion – I don't know exactly. Xcode didn't see a correct name of the object in the simplest hierarchy of a Scene graph
: Instead of pHelicopter1
it just showed Helicopter
. My 3D object was made from pCube1
using polygonal Extrude
tool.
Here's the final code and it works fine:
import ARKit
import SceneKit.ModelIO
//..........................................................
var scene = SCNScene(named: "art.scnassets/EmptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let helicopterNode = scene.rootNode.childNode(withName: "pHelicopter1",
recursively: true)
let geometry = helicopterNode!.geometry!
let mdlMesh = MDLMesh(scnGeometry: geometry)
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
else
print("Invalid path!")
add a comment |
Was it an error in Maya binary file, or an error of usdz
conversion – I don't know exactly. Xcode didn't see a correct name of the object in the simplest hierarchy of a Scene graph
: Instead of pHelicopter1
it just showed Helicopter
. My 3D object was made from pCube1
using polygonal Extrude
tool.
Here's the final code and it works fine:
import ARKit
import SceneKit.ModelIO
//..........................................................
var scene = SCNScene(named: "art.scnassets/EmptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let helicopterNode = scene.rootNode.childNode(withName: "pHelicopter1",
recursively: true)
let geometry = helicopterNode!.geometry!
let mdlMesh = MDLMesh(scnGeometry: geometry)
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
else
print("Invalid path!")
add a comment |
Was it an error in Maya binary file, or an error of usdz
conversion – I don't know exactly. Xcode didn't see a correct name of the object in the simplest hierarchy of a Scene graph
: Instead of pHelicopter1
it just showed Helicopter
. My 3D object was made from pCube1
using polygonal Extrude
tool.
Here's the final code and it works fine:
import ARKit
import SceneKit.ModelIO
//..........................................................
var scene = SCNScene(named: "art.scnassets/EmptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let helicopterNode = scene.rootNode.childNode(withName: "pHelicopter1",
recursively: true)
let geometry = helicopterNode!.geometry!
let mdlMesh = MDLMesh(scnGeometry: geometry)
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
else
print("Invalid path!")
Was it an error in Maya binary file, or an error of usdz
conversion – I don't know exactly. Xcode didn't see a correct name of the object in the simplest hierarchy of a Scene graph
: Instead of pHelicopter1
it just showed Helicopter
. My 3D object was made from pCube1
using polygonal Extrude
tool.
Here's the final code and it works fine:
import ARKit
import SceneKit.ModelIO
//..........................................................
var scene = SCNScene(named: "art.scnassets/EmptyScene.scn")!
if let filePath = Bundle.main.path(forResource: "Helicopter",
ofType: "usdz",
inDirectory: "art.scnassets")
let refURL = URL(fileURLWithPath: filePath)
let mdlAsset = MDLAsset(url: refURL)
scene = SCNScene(mdlAsset: mdlAsset)
let helicopterNode = scene.rootNode.childNode(withName: "pHelicopter1",
recursively: true)
let geometry = helicopterNode!.geometry!
let mdlMesh = MDLMesh(scnGeometry: geometry)
try! mdlMesh.makeVerticesUniqueAndReturnError()
let flattenedGeometry = SCNGeometry(mdlMesh: mdlMesh)
let flattenedNode = SCNNode(geometry: flattenedGeometry)
scene.rootNode.addChildNode(flattenedNode)
else
print("Invalid path!")
edited Nov 16 '18 at 12:43
answered Nov 16 '18 at 12:17
ARGeoARGeo
5,59952753
5,59952753
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52807356%2fcant-feed-a-mdlmesh-container-with-3d-model-as-scngeometry%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Have you tried
let helicopterGeo = refNode!.geometry
?– Steve O'Connor
Oct 17 '18 at 9:23