public void CreateLight() { float pi = (float)Math.PI; var light = SCNLight.Create(); var lightNode = SCNNode.Create(); light.LightType = SCNLightType.Omni; light.Color = UIColor.White; lightNode.Light = light; lightNode.Position = new SCNVector3(-90, 40, 60); gameScene.RootNode.AddChildNode(lightNode); var directionLight = SCNNode.Create(); directionLight.Light = SCNLight.Create(); directionLight.Light.LightType = SCNLightType.Directional; directionLight.Light.CastsShadow = true; directionLight.Light.ShadowMode = SCNShadowMode.Deferred; directionLight.Light.CategoryBitMask = (System.nuint)(-1); directionLight.Light.AutomaticallyAdjustsShadowProjection = true; directionLight.Light.MaximumShadowDistance = 50; directionLight.Position = new SCNVector3(-90, 40, 60); directionLight.Rotation = new SCNVector4(x: -1, y: 0, z: 0, w: pi / 2); directionLight.Light.ShadowColor = new UIColor(white: 0, alpha: 0.5f); gameScene.RootNode.AddChildNode(directionLight); }
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); }
public override void PresentStep(int index, PresentationViewController presentationViewController) { SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 0; switch (index) { case 0: // Set the slide's title and subtile and add some text TextManager.SetTitle("Node Attributes"); TextManager.SetSubtitle("Lights"); TextManager.AddBulletAtLevel("SCNLight", 0); TextManager.AddBulletAtLevel("Four light types", 0); TextManager.AddBulletAtLevel("Omni", 1); TextManager.AddBulletAtLevel("Directional", 1); TextManager.AddBulletAtLevel("Spot", 1); TextManager.AddBulletAtLevel("Ambient", 1); break; case 1: // Add some code var codeExampleNode = TextManager.AddCode("#aNode.#Light# = SCNLight.Create (); \naNode.Light.LightType = SCNLightType.Omni;#"); codeExampleNode.Position = new SCNVector3(14, 11, 1); // Add a light to the scene LightNode = SCNNode.Create(); LightNode.Light = SCNLight.Create(); LightNode.Light.LightType = SCNLightType.Omni; LightNode.Light.Color = NSColor.Black; // initially off LightNode.Light.SetAttribute(new NSNumber(30), SCNLightAttribute.AttenuationStartKey); LightNode.Light.SetAttribute(new NSNumber(40), SCNLightAttribute.AttenuationEndKey); LightNode.Position = new SCNVector3(5, 3.5f, 0); ContentNode.AddChildNode(LightNode); // Load two images to help visualize the light (on and off) LightOffImageNode = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-off", "tiff"), 7, false); LightOnImageNode = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-on", "tiff"), 7, false); LightOnImageNode.Opacity = 0; LightNode.AddChildNode(LightOnImageNode); LightNode.AddChildNode(LightOffImageNode); break; case 2: // Switch the light on SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1; LightNode.Light.Color = NSColor.FromCalibratedRgba(1, 1, 0.8f, 1); LightOnImageNode.Opacity = 1.0f; LightOffImageNode.Opacity = 0.0f; SCNTransaction.Commit(); break; } SCNTransaction.Commit(); }
SCNNode MakeAmbiantLight(float intensity) { var light = new SCNLight(); light.LightType = SCNLightType.Ambient; light.Color = UIColor.White; light.Intensity = intensity; var node = new SCNNode(); node.Light = light; return(node); }
SCNNode MakeDirectionalLight(float intensity) { var light = new SCNLight(); light.LightType = SCNLightType.Directional; light.Color = UIColor.White; light.Intensity = intensity; var node = new SCNNode(); node.Light = light; return(node); }
internal static SCNNode Load3DModel(NSUrl url) { var scene = SCNScene.FromUrl(url, new NSDictionary(), out var err); if (scene == null) { Console.WriteLine($"Error: failed to load 3D model from file {url}."); if (err != null) { Console.WriteLine(err.ToString()); } return(null); } var node = new SCNNode(); foreach (var child in scene.RootNode.ChildNodes) { node.AddChildNode(child); } // If there are no light sources in the model, add some var lightNodes = node.ChildNodes.Where(child => child.Light != null); if (lightNodes.Count() == 0) { var ambientLight = new SCNLight { LightType = SCNLightType.Ambient, Intensity = 100 }; var ambientLightNode = new SCNNode(); ambientLightNode.Light = ambientLight; node.AddChildNode(ambientLightNode); var directionLight = new SCNLight { LightType = SCNLightType.Directional, Intensity = 500 }; var directionalLightNode = new SCNNode(); directionalLightNode.Light = directionLight; node.AddChildNode(directionalLightNode); } return(node); }
private void initLight() { // omnidirectional light var light = SCNLight.Create(); var lightNode = SCNNode.Create(); light.LightType = SCNLightType.Omni; light.Color = UIColor.White; lightNode.Light = light; lightNode.Position = new SCNVector3(-40, 40, 60); scene.RootNode.AddChildNode(lightNode); // ambient light var ambientLight = SCNLight.Create(); var ambientLightNode = SCNNode.Create(); ambientLight.LightType = SCNLightType.Ambient; ambientLight.Color = UIColor.White; ambientLightNode.Light = ambientLight; scene.RootNode.AddChildNode(ambientLightNode); }
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); }
public override void PresentStep(int index, PresentationViewController presentationViewController) { switch (index) { case 0: // Set the slide's title and subtitle TextManager.SetTitle("Scene Graph"); TextManager.SetSubtitle("Summary"); break; case 1: // A node that will help visualize the position of the stars WireframeBoxNode = SCNNode.Create(); WireframeBoxNode.Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 4)); WireframeBoxNode.Geometry = SCNBox.Create(1, 1, 1, 0); WireframeBoxNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/box_wireframe", "png")); WireframeBoxNode.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant; // no lighting WireframeBoxNode.Geometry.FirstMaterial.DoubleSided = true; // double sided // Sun SunNode = SCNNode.Create(); SunNode.Position = new SCNVector3(0, 30, 0); ContentNode.AddChildNode(SunNode); SunNode.AddChildNode((SCNNode)WireframeBoxNode.Copy()); // Earth-rotation (center of rotation of the Earth around the Sun) var earthRotationNode = SCNNode.Create(); SunNode.AddChildNode(earthRotationNode); // Earth-group (will contain the Earth, and the Moon) EarthGroupNode = SCNNode.Create(); EarthGroupNode.Position = new SCNVector3(15, 0, 0); earthRotationNode.AddChildNode(EarthGroupNode); // Earth EarthNode = (SCNNode)WireframeBoxNode.Copy(); EarthNode.Position = new SCNVector3(0, 0, 0); EarthGroupNode.AddChildNode(EarthNode); // Rotate the Earth around the Sun var animation = CABasicAnimation.FromKeyPath("rotation"); animation.Duration = 10.0f; animation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); animation.RepeatCount = float.MaxValue; earthRotationNode.AddAnimation(animation, new NSString("earth rotation around sun")); // Rotate the Earth animation = CABasicAnimation.FromKeyPath("rotation"); animation.Duration = 1.0f; animation.From = NSValue.FromVector(new SCNVector4(0, 1, 0, 0)); animation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); animation.RepeatCount = float.MaxValue; EarthNode.AddAnimation(animation, new NSString("earth rotation")); break; case 2: // Moon-rotation (center of rotation of the Moon around the Earth) var moonRotationNode = SCNNode.Create(); EarthGroupNode.AddChildNode(moonRotationNode); // Moon MoonNode = (SCNNode)WireframeBoxNode.Copy(); MoonNode.Position = new SCNVector3(5, 0, 0); moonRotationNode.AddChildNode(MoonNode); // Rotate the moon around the Earth animation = CABasicAnimation.FromKeyPath("rotation"); animation.Duration = 1.5f; animation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); animation.RepeatCount = float.MaxValue; moonRotationNode.AddAnimation(animation, new NSString("moon rotation around earth")); // Rotate the moon animation = CABasicAnimation.FromKeyPath("rotation"); animation.Duration = 1.5f; animation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); animation.RepeatCount = float.MaxValue; MoonNode.AddAnimation(animation, new NSString("moon rotation")); break; case 3: // Add geometries (spheres) to represent the stars SunNode.Geometry = SCNSphere.Create(2.5f); EarthNode.Geometry = SCNSphere.Create(1.5f); MoonNode.Geometry = SCNSphere.Create(0.75f); // Add a textured plane to represent Earth's orbit var earthOrbit = SCNNode.Create(); earthOrbit.Opacity = 0.4f; earthOrbit.Geometry = SCNPlane.Create(31, 31); earthOrbit.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/orbit", "png")); earthOrbit.Geometry.FirstMaterial.Diffuse.MipFilter = SCNFilterMode.Linear; earthOrbit.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2)); earthOrbit.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant; // no lighting SunNode.AddChildNode(earthOrbit); break; case 4: // Add a halo to the Sun (a simple textured plane that does not write to depth) SunHaloNode = SCNNode.Create(); SunHaloNode.Geometry = SCNPlane.Create(30, 30); SunHaloNode.Rotation = new SCNVector4(1, 0, 0, Pitch * (float)(Math.PI / 180.0f)); SunHaloNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/sun-halo", "png")); SunHaloNode.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant; // no lighting SunHaloNode.Geometry.FirstMaterial.WritesToDepthBuffer = false; // do not write to depth SunHaloNode.Opacity = 0.2f; SunNode.AddChildNode(SunHaloNode); // Add materials to the stars EarthNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-diffuse-mini", "jpg")); EarthNode.Geometry.FirstMaterial.Emission.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-emissive-mini", "jpg")); EarthNode.Geometry.FirstMaterial.Specular.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-specular-mini", "jpg")); MoonNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/moon", "jpg")); SunNode.Geometry.FirstMaterial.Multiply.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/sun", "jpg")); SunNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/sun", "jpg")); SunNode.Geometry.FirstMaterial.Multiply.Intensity = 0.5f; SunNode.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant; SunNode.Geometry.FirstMaterial.Multiply.WrapS = SunNode.Geometry.FirstMaterial.Diffuse.WrapS = SunNode.Geometry.FirstMaterial.Multiply.WrapT = SunNode.Geometry.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Repeat; EarthNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = MoonNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = SunNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true; EarthNode.Geometry.FirstMaterial.Shininess = 0.1f; EarthNode.Geometry.FirstMaterial.Specular.Intensity = 0.5f; MoonNode.Geometry.FirstMaterial.Specular.Contents = NSColor.Gray; // Achieve a lava effect by animating textures animation = CABasicAnimation.FromKeyPath("contentsTransform"); animation.Duration = 10.0f; var animationTransform1 = CATransform3D.MakeTranslation(0, 0, 0); animationTransform1 = animationTransform1.Concat(CATransform3D.MakeScale(3, 3, 3)); var animationTransform2 = CATransform3D.MakeTranslation(1, 0, 0); animationTransform2 = animationTransform1.Concat(CATransform3D.MakeScale(3, 3, 3)); animation.From = NSValue.FromCATransform3D(animationTransform1); animation.To = NSValue.FromCATransform3D(animationTransform2); animation.RepeatCount = float.MaxValue; SunNode.Geometry.FirstMaterial.Diffuse.AddAnimation(animation, new NSString("sun-texture")); animation = CABasicAnimation.FromKeyPath("contentsTransform"); animation.Duration = 30.0f; animationTransform1 = CATransform3D.MakeTranslation(0, 0, 0); animationTransform1 = animationTransform1.Concat(CATransform3D.MakeScale(5, 5, 5)); animationTransform2 = CATransform3D.MakeTranslation(1, 0, 0); animationTransform2 = animationTransform1.Concat(CATransform3D.MakeScale(5, 5, 5)); animation.From = NSValue.FromCATransform3D(animationTransform1); animation.To = NSValue.FromCATransform3D(animationTransform2); animation.RepeatCount = float.MaxValue; SunNode.Geometry.FirstMaterial.Multiply.AddAnimation(animation, new NSString("sun-texture2")); break; case 5: // We will turn off all the lights in the scene and add a new light // to give the impression that the Sun lights the scene var lightNode = SCNNode.Create(); lightNode.Light = SCNLight.Create(); lightNode.Light.Color = NSColor.Black; // initially switched off lightNode.Light.LightType = SCNLightType.Omni; SunNode.AddChildNode(lightNode); // Configure attenuation distances because we don't want to light the floor lightNode.Light.SetAttribute(new NSNumber(20), SCNLightAttribute.AttenuationEndKey); lightNode.Light.SetAttribute(new NSNumber(19.5), SCNLightAttribute.AttenuationStartKey); // Animation SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1; lightNode.Light.Color = NSColor.White; // switch on presentationViewController.UpdateLightingWithIntensities(new float[] { 0.0f }); //switch off all the other lights SunHaloNode.Opacity = 0.5f; // make the halo stronger SCNTransaction.Commit(); break; } }
public override void SetupSlide(PresentationViewController presentationViewController) { // Set the slide's title and add some code TextManager.SetTitle("Materials"); TextManager.AddBulletAtLevel("Diffuse", 0); TextManager.AddBulletAtLevel("Ambient", 0); TextManager.AddBulletAtLevel("Specular", 0); TextManager.AddBulletAtLevel("Normal", 0); TextManager.AddBulletAtLevel("Reflective", 0); TextManager.AddBulletAtLevel("Emission", 0); TextManager.AddBulletAtLevel("Transparent", 0); TextManager.AddBulletAtLevel("Multiply", 0); // Create a node for Earth and another node to display clouds // Use the 'pivot' property to tilt Earth because we don't want to see the north pole. EarthNode = SCNNode.Create(); EarthNode.Pivot = SCNMatrix4.CreateFromAxisAngle(new SCNVector3(1, 0, 0), (float)(Math.PI * 0.1f)); EarthNode.Position = new SCNVector3(6, 7.2f, -2); EarthNode.Geometry = SCNSphere.Create(7.2f); CloudsNode = SCNNode.Create(); CloudsNode.Geometry = SCNSphere.Create(7.9f); GroundNode.AddChildNode(EarthNode); EarthNode.AddChildNode(CloudsNode); // Initially hide everything EarthNode.Opacity = 1.0f; CloudsNode.Opacity = 0.5f; EarthNode.Geometry.FirstMaterial.Ambient.Intensity = 1; EarthNode.Geometry.FirstMaterial.Normal.Intensity = 1; EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.2f; EarthNode.Geometry.FirstMaterial.Reflective.Contents = NSColor.White; EarthNode.Geometry.FirstMaterial.FresnelExponent = 3; EarthNode.Geometry.FirstMaterial.Emission.Intensity = 1; EarthNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/earth/earth-diffuse", "jpg")); EarthNode.Geometry.FirstMaterial.Shininess = 0.1f; EarthNode.Geometry.FirstMaterial.Specular.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/earth/earth-specular", "jpg")); EarthNode.Geometry.FirstMaterial.Specular.Intensity = 0.8f; EarthNode.Geometry.FirstMaterial.Normal.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/earth/earth-bump", "png")); EarthNode.Geometry.FirstMaterial.Normal.Intensity = 1.3f; EarthNode.Geometry.FirstMaterial.Emission.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/earth/earth-emissive", "jpg")); //EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 1.0f; // This effect can also be achieved with an image with some transparency set as the contents of the 'diffuse' property CloudsNode.Geometry.FirstMaterial.Transparent.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/earth/cloudsTransparency", "png")); CloudsNode.Geometry.FirstMaterial.TransparencyMode = SCNTransparencyMode.RgbZero; // Use a shader modifier to display an environment map independently of the lighting model used /*EarthNode.Geometry.ShaderModifiers = new SCNShaderModifiers { * EntryCGPointragment = " _output.color.rgb -= _surface.reflective.rgb * _lightingContribution.diffuse;" + "_output.color.rgb += _surface.reflective.rgb;" + };*/ // Add animations var rotationAnimation = CABasicAnimation.FromKeyPath("rotation"); rotationAnimation.Duration = 40.0f; rotationAnimation.RepeatCount = float.MaxValue; rotationAnimation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); EarthNode.AddAnimation(rotationAnimation, new NSString("earthNodeAnimation")); rotationAnimation.Duration = 100.0f; CloudsNode.AddAnimation(rotationAnimation, new NSString("cloudsNodeAnimation")); //animate light var lightHandleNode = SCNNode.Create(); var lightNode = SCNNode.Create(); lightNode.Light = SCNLight.Create(); lightNode.Light.LightType = SCNLightType.Directional; lightNode.Light.CastsShadow = true; lightHandleNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -NMath.PI * 2, 0, 12))); lightHandleNode.AddChildNode(lightNode); EarthNode.AddChildNode(lightHandleNode); }
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 PresentStep(int index, PresentationViewController presentationViewController) { switch (index) { case 0: break; case 1: TextManager.HighlightBullet(0); StaticShadowNode.Opacity = 1; var node = TextManager.AddCode("#aMaterial.#multiply#.contents = aShadowMap;#"); node.Position = new SCNVector3(node.Position.X, node.Position.Y - 4, node.Position.Z); foreach (var child in node.ChildNodes) { child.RenderingOrder = 1; foreach (var m in child.Geometry.Materials) { m.ReadsFromDepthBuffer = false; } } break; case 2: //move the tree PalmTree.RunAction(SCNAction.RotateBy(0, NMath.PI * 4, 0, 8)); break; case 3: TextManager.FadesIn = true; TextManager.FadeOutText(SlideTextManager.TextType.Code); TextManager.AddEmptyLine(); node = TextManager.AddCode("#aLight.#castsShadow# = YES;#"); foreach (SCNNode child in node.ChildNodes) { child.RenderingOrder = 1; foreach (SCNMaterial m in child.Geometry.Materials) { m.ReadsFromDepthBuffer = false; m.WritesToDepthBuffer = false; } } node.Position = new SCNVector3(node.Position.X, node.Position.Y - 6, node.Position.Z); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 0.75f; var spot = presentationViewController.SpotLight; OldSpotShadowColor = spot.Light.ShadowColor; spot.Light.ShadowColor = NSColor.Black; spot.Light.ShadowRadius = 3; var tp = TextManager.TextNode.Position; var superNode = presentationViewController.CameraNode.ParentNode.ParentNode; var p0 = GroundNode.ConvertPositionToNode(SCNVector3.Zero, null); var p1 = GroundNode.ConvertPositionToNode(new SCNVector3(20, 0, 0), null); var tr = new SCNVector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); var p = superNode.Position; p.X += tr.X; p.Y += tr.Y; p.Z += tr.Z; tp.X += 20; tp.Y += 0; tp.Z += 0; superNode.Position = p; TextManager.TextNode.Position = tp; SCNTransaction.Commit(); TextManager.HighlightBullet(1); break; case 4: //move the light var lightPivot = SCNNode.Create(); lightPivot.Position = Character.Position; GroundNode.AddChildNode(lightPivot); spot = presentationViewController.SpotLight; OldSpotPosition = spot.Position; OldSpotParent = spot.ParentNode; OldSpotZNear = spot.Light.ZNear; spot.Light.ZNear = 20; spot.Position = lightPivot.ConvertPositionFromNode(spot.Position, spot.ParentNode); lightPivot.AddChildNode(spot); //add an object to represent the light var lightModel = SCNNode.Create(); var lightHandle = SCNNode.Create(); var cone = SCNCone.Create(0, 0.5f, 1); cone.RadialSegmentCount = 10; cone.HeightSegmentCount = 5; lightModel.Geometry = cone; lightModel.Geometry.FirstMaterial.Emission.Contents = NSColor.Yellow; lightHandle.Position = new SCNVector3(spot.Position.X * DIST, spot.Position.Y * DIST, spot.Position.Z * DIST); lightModel.CastsShadow = false; lightModel.EulerAngles = new SCNVector3(NMath.PI / 2, 0, 0); lightHandle.AddChildNode(lightModel); lightHandle.Constraints = new SCNConstraint[] { SCNLookAtConstraint.Create(Character) }; lightPivot.AddChildNode(lightHandle); LightHandle = lightHandle; var animation = CABasicAnimation.FromKeyPath("eulerAngles.z"); animation.From = new NSNumber((nfloat)(Math.PI / 4) * 1.7f); animation.To = new NSNumber((nfloat)(-Math.PI / 4) * 0.3f); animation.Duration = 4; animation.AutoReverses = true; animation.RepeatCount = float.MaxValue; animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); animation.TimeOffset = animation.Duration / 2; lightPivot.AddAnimation(animation, new NSString("lightAnim")); break; case 5: TextManager.FadeOutText(SlideTextManager.TextType.Code); var text = TextManager.AddCode("#aLight.#shadowMode# =\n#SCNShadowModeModulated#;\naLight.#gobo# = anImage;#"); text.Position = new SCNVector3(text.Position.X, text.Position.Y - 6, text.Position.Z); text.EnumerateChildNodes((SCNNode child, out bool stop) => { stop = false; child.RenderingOrder = 1; foreach (var m in child.Geometry.Materials) { m.ReadsFromDepthBuffer = false; m.WritesToDepthBuffer = false; } return(stop); }); LightHandle.RemoveFromParentNode(); RestoreSpotPosition(presentationViewController); TextManager.HighlightBullet(2); spot = presentationViewController.SpotLight; spot.Light.CastsShadow = false; var head = Character.FindChildNode("Bip001_Pelvis", true); node = SCNNode.Create(); node.Light = SCNLight.Create(); node.Light.LightType = SCNLightType.Spot; node.Light.SpotOuterAngle = 30; node.Constraints = new SCNConstraint[] { SCNLookAtConstraint.Create(head) }; node.Position = new SCNVector3(0, 220, 0); node.Light.ZNear = 10; node.Light.ZFar = 1000; node.Light.Gobo.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/blobShadow", "jpg")); node.Light.Gobo.Intensity = 0.65f; node.Light.ShadowMode = SCNShadowMode.Modulated; //exclude character from shadow node.Light.CategoryBitMask = 0x1; Character.FindNodes((SCNNode child, out bool stop) => { stop = false; child.CategoryBitMask = 0x2; return(stop); }); Projector = node; Character.AddChildNode(node); break; } }
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(); }