public override void ViewDidLoad() { Title = "ARKit"; View = sceneView; sceneView.ShowsStatistics = true; sceneView.AutomaticallyUpdatesLighting = true; sceneView.Scene = SCNScene.Create(); var root = sceneView.Scene.RootNode; var cameraNode = SCNNode.Create(); cameraNode.Camera = SCNCamera.Create(); root.AddChildNode(cameraNode); var lightNode = SCNNode.Create(); cameraNode.Light = SCNLight.Create(); root.AddChildNode(lightNode); var label = new UILabel(new CGRect(10, 10, 300, 30)); View.AddSubview(label); }
void Initialize() { cameraNode.Camera = SCNCamera.Create(); cameraNode.Camera.YFov = 60; cameraNode.Camera.ZNear = 1; cameraNode.Camera.ZFar = 10000; cameraNode.Position = new SCNVector3(0, 0, 300); scene.RootNode.Add(cameraNode); }
private SCNScene SetupScene() { var scene = SCNScene.Create(); SetupInvironment(scene); SetupSceneElements(scene); vehicleNode = SetupVehicle(scene); cameraNode = SCNNode.Create(); cameraNode.Camera = SCNCamera.Create(); cameraNode.Camera.ZFar = 500f; cameraNode.Position = new SCNVector3(0f, 60f, 50f); cameraNode.Rotation = new SCNVector4(1f, 0f, 0f, -(float)Math.PI / 4f * 0.75f); scene.RootNode.AddChildNode(cameraNode); return(scene); }
public AwesomerRealityViewController() { Title = "ARKit"; View = sceneView; sceneView.Delegate = new Del(); sceneView.ShowsStatistics = true; sceneView.AutomaticallyUpdatesLighting = true; sceneView.Scene = SCNScene.Create(); var root = sceneView.Scene.RootNode; var cameraNode = SCNNode.Create(); cameraNode.Camera = SCNCamera.Create(); root.AddChildNode(cameraNode); var lightNode = SCNNode.Create(); cameraNode.Light = SCNLight.Create(); root.AddChildNode(lightNode); }
private SCNNode SetupVehicle(SCNScene scene) { var carScene = SCNScene.FromFile("rc_car", ResourceManager.ResourceFolder, (NSDictionary)null); var chassisNode = carScene.RootNode.FindChildNode("rccarBody", false); chassisNode.Position = new SCNVector3(0f, 10f, 30f); chassisNode.Rotation = new SCNVector4(0f, 1f, 0f, (float)Math.PI); var body = SCNPhysicsBody.CreateDynamicBody(); body.AllowsResting = false; body.Mass = 80f; body.Restitution = 0.1f; body.Friction = 0.5f; body.RollingFriction = 0f; chassisNode.PhysicsBody = body; var frontCameraNode = SCNNode.Create(); frontCameraNode.Position = new SCNVector3(0f, 3.5f, 2.5f); frontCameraNode.Rotation = new SCNVector4(0f, 1f, 0f, (float)Math.PI); frontCameraNode.Camera = SCNCamera.Create(); frontCameraNode.Camera.XFov = 75f; frontCameraNode.Camera.ZFar = 500f; chassisNode.AddChildNode(frontCameraNode); scene.RootNode.AddChildNode(chassisNode); var pipeNode = chassisNode.FindChildNode("pipe", true); reactor = SCNParticleSystem.Create("reactor", ResourceManager.ResourceFolder); reactor.ParticleImage = ResourceManager.GetResourcePath("spark.png"); reactorDefaultBirthRate = reactor.BirthRate; reactor.BirthRate = 0; pipeNode.AddParticleSystem(reactor); SCNNode wheel0Node = chassisNode.FindChildNode("wheelLocator_FL", true); SCNNode wheel1Node = chassisNode.FindChildNode("wheelLocator_FR", true); SCNNode wheel2Node = chassisNode.FindChildNode("wheelLocator_RL", true); SCNNode wheel3Node = chassisNode.FindChildNode("wheelLocator_RR", true); var wheel0 = SCNPhysicsVehicleWheel.Create(wheel0Node); var wheel1 = SCNPhysicsVehicleWheel.Create(wheel1Node); var wheel2 = SCNPhysicsVehicleWheel.Create(wheel2Node); var wheel3 = SCNPhysicsVehicleWheel.Create(wheel3Node); var min = SCNVector3.Zero; var max = SCNVector3.Zero; wheel0Node.GetBoundingBox(ref min, ref max); float wheelHalfWidth = 0.5f * (max.X - min.X); wheel0.ConnectionPosition = SCNVector3.Add(wheel0Node.ConvertPositionToNode(SCNVector3.Zero, chassisNode), new SCNVector3(wheelHalfWidth, 0f, 0f)); wheel1.ConnectionPosition = SCNVector3.Subtract(wheel1Node.ConvertPositionToNode(SCNVector3.Zero, chassisNode), new SCNVector3(wheelHalfWidth, 0f, 0f)); wheel2.ConnectionPosition = SCNVector3.Add(wheel2Node.ConvertPositionToNode(SCNVector3.Zero, chassisNode), new SCNVector3(wheelHalfWidth, 0f, 0f)); wheel3.ConnectionPosition = SCNVector3.Subtract(wheel3Node.ConvertPositionToNode(SCNVector3.Zero, chassisNode), new SCNVector3(wheelHalfWidth, 0f, 0f)); var vehicle = SCNPhysicsVehicle.Create(chassisNode.PhysicsBody, new SCNPhysicsVehicleWheel[] { wheel0, wheel1, wheel2, wheel3 }); scene.PhysicsWorld.AddBehavior(vehicle); this.vehicle = vehicle; return(chassisNode); }
void Setup() { // create a new scene var scene = SCNScene.FromFile("art.scnassets/ship"); // create and add a camera to the scene var cameraNode = SCNNode.Create(); cameraNode.Camera = SCNCamera.Create(); scene.RootNode.AddChildNode(cameraNode); // place the camera cameraNode.Position = new SCNVector3(0, 0, 15); // create and add a light to the scene var lightNode = SCNNode.Create(); lightNode.Light = SCNLight.Create(); lightNode.Light.LightType = SCNLightType.Omni; lightNode.Position = new SCNVector3(0, 10, 10); scene.RootNode.AddChildNode(lightNode); // create and add an ambient light to the scene var ambientLightNode = SCNNode.Create(); ambientLightNode.Light = SCNLight.Create(); ambientLightNode.Light.LightType = SCNLightType.Ambient; ambientLightNode.Light.Color = SKColor.DarkGray; scene.RootNode.AddChildNode(ambientLightNode); // retrieve the ship node var ship = scene.RootNode.FindChildNode("ship", true); // animate the 3d object #if __IOS__ ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 2, 0, 1))); #else var animation = CABasicAnimation.FromKeyPath("rotation"); animation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, NMath.PI * 2)); animation.Duration = 3; animation.RepeatCount = float.MaxValue; //repeat forever ship.AddAnimation(animation, null); #endif // retrieve the SCNView var scnView = (SCNView)View; // set the scene to the view scnView.Scene = scene; // allows the user to manipulate the camera scnView.AllowsCameraControl = true; // show statistics such as fps and timing information scnView.ShowsStatistics = true; // configure the view scnView.BackgroundColor = SKColor.Black; #if __IOS__ // add a tap gesture recognizer var tapGesture = new UITapGestureRecognizer(HandleTap); var gestureRecognizers = new List <UIGestureRecognizer> (); gestureRecognizers.Add(tapGesture); gestureRecognizers.AddRange(scnView.GestureRecognizers); scnView.GestureRecognizers = gestureRecognizers.ToArray(); #endif }
public override void ViewDidLoad() { base.ViewDidLoad(); // create a new scene var scene = SCNScene.FromFile("art.scnassets/ship"); // create and add a camera to the scene var cameraNode = SCNNode.Create(); cameraNode.Camera = SCNCamera.Create(); scene.RootNode.AddChildNode(cameraNode); // place the camera cameraNode.Position = new SCNVector3(0, 0, 15); // create and add a light to the scene var lightNode = SCNNode.Create(); lightNode.Light = SCNLight.Create(); lightNode.Light.LightType = SCNLightType.Omni; lightNode.Position = new SCNVector3(0, 10, 10); scene.RootNode.AddChildNode(lightNode); // create and add an ambient light to the scene var ambientLightNode = SCNNode.Create(); ambientLightNode.Light = SCNLight.Create(); ambientLightNode.Light.LightType = SCNLightType.Ambient; ambientLightNode.Light.Color = UIColor.DarkGray; scene.RootNode.AddChildNode(ambientLightNode); // retrieve the ship node var ship = scene.RootNode.FindChildNode("ship", true); // animate the 3d object ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 2, 0, 1))); // retrieve the SCNView var scnView = (SCNView)View; // set the scene to the view scnView.Scene = scene; // allows the user to manipulate the camera scnView.AllowsCameraControl = true; // show statistics such as fps and timing information scnView.ShowsStatistics = true; // configure the view scnView.BackgroundColor = UIColor.Black; // add a tap gesture recognizer var tapGesture = new UITapGestureRecognizer(HandleTap); var gestureRecognizers = new List <UIGestureRecognizer> (); gestureRecognizers.Add(tapGesture); gestureRecognizers.AddRange(scnView.GestureRecognizers); scnView.GestureRecognizers = gestureRecognizers.ToArray(); }