Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/SceneKit/SceneKit Images
Function:
Required plugins for this example: MBS MacCG Plugin, MBS Main Plugin, MBS MacBase Plugin, MBS Mac64bit Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/SceneKit/SceneKit Images
This example is the version from Mon, 3rd Feb 2019.
Project "SceneKit Images.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() #if Target64Bit and TargetMacOS then // okay #else MsgBox "Please switch project to 64-bit and run on MacOS." #endif End EventHandler
End Class
Class MainWindow Inherits Window
Control MyControl Inherits SCNControlMBS
ControlInstance MyControl Inherits SCNControlMBS
EventHandler Sub Open() MyView = me.View MyScene = new SCNSceneMBS MyView.scene = MyScene MyView.backgroundColor = NSColorMBS.blackColor MyView.autoenablesDefaultLighting = true Myview.allowsCameraControl = true // show three cylinders. dim c1 as new SCNCylinderMBS(0.5, 100) dim c2 as new SCNCylinderMBS(0.5, 100) dim c3 as new SCNCylinderMBS(0.5, 100) dim n1 as new SCNNodeMBS(c1) dim n2 as new SCNNodeMBS(c2) dim n3 as new SCNNodeMBS(c3) const pi = 3.1415926535897932384626433 n2.eulerAngles = SCNVector3MBS.Vector(pi/2, 0, 0) n3.eulerAngles = SCNVector3MBS.Vector(0, 0, pi/2) MyScene.rootNode.addChildNode n1 MyScene.rootNode.addChildNode n2 MyScene.rootNode.addChildNode n3 End EventHandler
End Control
Control SegmentedControl1 Inherits SegmentedControl
ControlInstance SegmentedControl1 Inherits SegmentedControl
EventHandler Sub Action(itemIndex as integer) Select case itemIndex case 0 CreateImage case 1 CreateCube case 2 CreateFading case 3 CreateCube3d end Select End EventHandler
End Control
Control MyTimer Inherits Timer
ControlInstance MyTimer Inherits Timer
EventHandler Sub Action() dim LastIndex as integer = NodeIndex NodeIndex = (NodeIndex + 1) mod (nodes.Ubound+1) nodes(LastIndex).runAction SCNActionMBS.fadeOut(2) nodes(NodeIndex).runAction SCNActionMBS.fadeIn(2) End EventHandler
End Control
Sub CreateCube() MyScene = new SCNSceneMBS dim pic as Picture = LogoMBS(500) dim box as new SCNBoxMBS(500, 500, 500, 0) box.firstMaterial.diffuse.contents = pic dim node as new SCNNodeMBS(box) MyScene.rootNode.addChildNode node // show scene MyView.scene = MyScene End Sub
Sub CreateCube3d() // See tutorial here: // https://code.tutsplus.com/tutorials/an-introduction-to-scenekit-fundamentals--cms-23847 const pi = 3.1415926535897932384626433 dim scene as new SCNSceneMBS myView.scene = scene dim camera as new SCNCameraMBS dim cameraNode as new SCNNodeMBS cameraNode.camera = camera cameraNode.position = SCNVector3MBS.Vector( -3.0, 3.0, 3.0) // spot light dim light as new SCNLightMBS light.type = SCNLightMBS.SCNLightTypeSpot light.spotInnerAngle = 30.0 light.spotOuterAngle = 80.0 light.castsShadow = true dim lightNode as new SCNNodeMBS lightNode.light = light lightNode.position = SCNVector3MBS.Vector(1.5, 1.5, 1.5) // add cube dim cubeGeometry as new SCNBoxMBS( 1.0, 1.0, 1.0, 0.0) dim cubeNode as new SCNNodeMBS(cubeGeometry) // ground plate dim planeGeometry as new SCNPlaneMBS( 50.0, 50.0) dim planeNode as new SCNNodeMBS(planeGeometry) planeNode.eulerAngles = SCNVector3MBS.Vector( -90 * pi / 180.0, 0, 0) planeNode.position = SCNVector3MBS.Vector( 0, -0.5, 0) // add some colors dim redMaterial as new SCNMaterialMBS redMaterial.diffuse.contents = NSColorMBS.redColor cubeGeometry.setMaterials array(redMaterial) dim greenMaterial as new SCNMaterialMBS greenMaterial.diffuse.contents = NSColorMBS.greenColor planeGeometry.setMaterials array(greenMaterial) // background light dim ambientLight as new SCNLightMBS ambientLight.type = SCNLightMBS.SCNLightTypeAmbient ambientLight.color = NSColorMBS.colorWithRGB( 0.2, 0.2, 0.2, 1.0) cameraNode.light = ambientLight // limit moving dim constraint as new SCNLookAtConstraintMBS(cubeNode) constraint.gimbalLockEnabled = true cameraNode.setConstraints array(constraint) lightNode.setConstraints array(constraint) scene.rootNode.addChildNode(lightNode) scene.rootNode.addChildNode(cameraNode) scene.rootNode.addChildNode(cubeNode) scene.rootNode.addChildNode(planeNode) End Sub
Sub CreateFading() MyScene = new SCNSceneMBS redim nodes(-1) dim w as integer = MyControl.Width dim h as integer = MyControl.Height dim pics() as Picture pics.Append NewPicture(MyControl.Width, MyControl.Height, &cFF0000) pics.Append NewPicture(MyControl.Width, MyControl.Height, &c00FF00) pics.Append NewPicture(MyControl.Width, MyControl.Height, &c0000FF) pics.Append NewPicture(MyControl.Width, MyControl.Height, &c00FFFF) pics.Append NewPicture(MyControl.Width, MyControl.Height, &cFF00FF) pics.Append NewPicture(MyControl.Width, MyControl.Height, &cFFFF00) pics.Append NewPicture(MyControl.Width, MyControl.Height, &cFFFFFF) dim rootNode as SCNNodeMBS = MyScene.rootNode dim planes() as SCNPlaneMBS dim sequence() as SCNActionMBS for each p as Picture in pics dim plane as new SCNPlaneMBS(w,h) plane.firstMaterial.diffuse.contents = p dim node as new SCNNodeMBS(plane) node.opacity = 0 nodes.append node rootNode.addChildNode node next NodeIndex = 0 nodes(NodeIndex).Opacity = 1 dim sequenceAction as SCNActionMBS = SCNActionMBS.sequence(sequence) rootNode.runAction sequenceAction MyView.play // show scene MyView.scene = MyScene 'dim p as SCNVector3MBS = MyView.pointOfView.Position // zoom to full for this view dim n as new SCNNodeMBS n.Position = SCNVector3MBS.Vector(0, 0, 380) MyView.pointOfView = n MyTimer.Mode = 2 End Sub
Sub CreateImage() MyScene = new SCNSceneMBS dim pic as Picture = LogoMBS(500) dim plane as new SCNPlaneMBS(500,500) plane.firstMaterial.diffuse.contents = pic dim node as new SCNNodeMBS(plane) MyScene.rootNode.addChildNode node // show scene MyView.scene = MyScene End Sub
Shared Function NewPicture(w as integer, h as integer, c as color) As Picture dim p as new Picture(w, h) dim g as Graphics = p.Graphics g.ForeColor = c g.FillRect 0, 0, w, h return p End Function
Note "Note"
Based on code found in the tutorial Introduction To SceneKit – Part 1 https://www.weheartswift.com/introduction-scenekit-part-1/
Note "Plugins needed"
MBS Xojo AVFoundation Plugin.xojo_plugin MBS Xojo Mac64bit Plugin.xojo_plugin MBS Xojo MacBase Plugin.xojo_plugin MBS Xojo MacCF Plugin.xojo_plugin MBS Xojo MacCG Plugin.xojo_plugin MBS Xojo MacCloud Plugin.xojo_plugin MBS Xojo MacCocoa Plugin.xojo_plugin MBS Xojo MacControls Plugin.xojo_plugin MBS Xojo Main Plugin.xojo_plugin
Property MyScene As SCNSceneMBS
Property MyView As SCNViewMBS
Property NodeIndex As Integer
Property nodes() As SCNNodeMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Mac64bit Plugin.

The biggest plugin in space...




Links
MBS Xojo Plugins