In ios-SceneKit display and Interactive 3D Modeling (PART 1), we introduced the simple use of SceneKit and mentioned the need to dynamically load scenes from a sandbox

Guess phase

Drag the footage to the Documents folder in the sandbox and the mock footage has been downloaded locally from the server

Next stitching material address, run after a dark, because there is nothing to look at the map. As you can see from the screenshot, I can’t see anything in the scene.

What if we put the footage Menchi. Dae in scnAssets like demo?

In practice, it’s the same thing. It’s nil.

SCN is a scene file that Xcode can recognize. The file itself is scene, so it is not nil. If DAE initializes the scene, DAE file is just added to the newly created scene as a node.

Exploratory stage

What are the special actions in the build process

// artLXF is just an example, you can change it to the name you want to display copySceneKitAssets art.scnAssets -o artlxf.scnAssetsCopy the code

SceneKit uses the copySceneKitAssets script to process art.scnAssets. This process also requires another scripting tool, scntool. These two files are stored in the following directory:

/Applications/Xcode.app/Contents/Developer/usr/bin/
Copy the code

As for the unknown process, it’s because I haven’t seen it in apple’s official documentation, or I can’t find it

Bold practice

Create a new folder on your desktop called LXFScene, create a new art folder and add the suffix “.scnAssets “, Dae, extract the two required files (copySceneKitAssets and scnTool) and put them into the LXFScene directory

./copySceneKitAssets art.scnassets -o artLXF.scnassets
Copy the code

Drag the new scnAssets into the sandbox’s Document folder, rename it to Art.scnAssets, and run the program again

SCNNode *mechiNode = scene.rootNode.childNodes.firstObject;
mechiNode.transform = SCNMatrix4MakeScale(5, 5, 5);
Copy the code

In this way, we can let the background first processed scnAssets folder package on the server, we download and decompress the use of good ~

Add click events to the model

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTest:)];
[scnView addGestureRecognizer:tap];
Copy the code
- (void)tapTest:(UITapGestureRecognizer *)tap {SCNVector3 projectedOrigin = [self.scnView projectPoint:SCNVector3Zero]; CGPoint vp = [tap locationInView:self.scnView]; SCNVector3 vpWithZ = SCNVector3Make(vp.x, vp.y, projectedOrigin.z); SCNVector3 worldPoint = [self.scnView unprojectPoint:vpWithZ]; NSLog(@"x: --- %f y: --- %f z: --- %f", worldPoint.x, worldPoint.y, worldPoint.z);
}
Copy the code

Finally, LXF3DSceneDemo is attached