protected override void BeginGame() { scene = new ARScene(this); scene.LoadScene(); quitter = componentFactory.GraphicsInputFactory.CreateInputComponent(); quitter.AddKeyDelegate(KeyCodes.Escape, new InputComponent.InputHandler(RequestEndGame)); }
private void OnRenderCreate() { // Create the base ARScene mScene = new ARScene(); mScene.SetListener(this); mViroView.Scene = mScene; // Create an ARImageTarget for the Tesla logo var teslaLogoTargetBmp = GetBitmapFromAssets("logo.png"); var teslaTarget = new ARImageTarget(teslaLogoTargetBmp, ARImageTarget.Orientation.Up, 0.188f); mScene.AddARImageTarget(teslaTarget); // Build the Tesla car Node and add it to the Scene. Set it to invisible: it will be made // visible when the ARImageTarget is found. var teslaNode = new Node(); InitCarModel(teslaNode); InitColorPickerModels(teslaNode); InitSceneLights(teslaNode); teslaNode.Visible = false; mScene.RootNode.AddChildNode(teslaNode); // Link the Node with the ARImageTarget, such that when the image target is // found, we'll render the Node. LinkTargetWithNode(teslaTarget, teslaNode); }
private void DisplayScene() { mScene = new ARScene(); // Add a listener to the scene so we can update the 'AR Initialized' text. mScene.SetListener(new ARSceneListener(this, mViroView)); // Add a light to the scene so our models show up mScene.RootNode.AddLight(new AmbientLight(Color.White, 1000f)); mViroView.Scene = mScene; var view = View.Inflate(this, Resource.Layout.viro_view_ar_hit_test_hud, mViroView); view.FindViewById <ImageButton>(Resource.Id.imageButton).Click += delegate { showPopup(); }; }
private void DisplayScene() { // Create the 3D AR scene, and display the point cloud mScene = new ARScene(); mScene.DisplayPointCloud(true); // Create a TrackedPlanesController to visually display identified planes. var controller = new TrackedPlanesController(this, mViroView); // Spawn a 3D Droid on the position where the user has clicked on a tracked plane. controller.AddOnPlaneClickListener(new ClickListener2(this)); mScene.SetListener(controller); // Add some lights to the scene; this will give the Android's some nice illumination. var rootNode = mScene.RootNode; var lightPositions = new List <Vector> { new Vector(-10, 10, 1), new Vector(10, 10, 1) }; const float intensity = 300; var lightColors = new List <Color> { Color.White, Color.White }; for (var i = 0; i < lightPositions.Count; i++) { var light = new OmniLight { Color = lightColors[i], Position = lightPositions[i], AttenuationStartDistance = 20, AttenuationEndDistance = 30, Intensity = intensity }; rootNode.AddLight(light); } //Add an HDR environment map to give the Android's more interesting ambient lighting. var environment = Texture.LoadRadianceHDRTexture(Android.Net.Uri.Parse("file:///android_asset/ibl_newport_loft.hdr")); mScene.LightingEnvironment = environment; mViroView.Scene = mScene; }
private void DisplayScene() { // Create the ARScene within which to load our ProductAR Experience mScene = new ARScene(); mMainLight = new AmbientLight(Color.ParseColor("#606060"), 400); mMainLight.InfluenceBitMask = 3; mScene.RootNode.AddLight(mMainLight); // Setup our 3D and HUD controls InitArCrosshair(); Init3DModelProduct(); InitArHud(); // Start our tracking UI when the scene is ready to be tracked mScene.SetListener(this); // Finally set the arScene on the renderer mViroView.Scene = mScene; }
private void OnRenderCreate() { // Create the base ARScene mScene = new ARScene(); // Create an ARImageTarget out of the Black Panther poster Bitmap blackPantherPoster = getBitmapFromAssets("logo.jpg"); mImageTarget = new ARImageTarget(blackPantherPoster, ARImageTarget.Orientation.Up, 0.188f); mScene.AddARImageTarget(mImageTarget); // Create a Node containing the Black Panther model mBlackPantherNode = initBlackPantherNode(); mBlackPantherNode.AddChildNode(initLightingNode()); mScene.RootNode.AddChildNode(mBlackPantherNode); mViroView.Scene = mScene; TrackImageNodeTargets(); }
private void Awake() { sInstance = this; // Record original scale mScaleOrigin = transform.localScale; // Record the music volume, then set it to 0 mAudioSource = GetComponent <AudioSource>(); if (mAudioSource != null) { mVolume = mAudioSource.volume; mAudioSource.volume = 0.0f; } // Hide or show the scene, depending on the platform #if UNITY_IOS && !UNITY_EDITOR Hide(); #else Show(); #endif }
private void Update() { // Use keyboard keys to test launch types #if UNITY_EDITOR if (Input.GetKeyUp(KeyCode.Alpha1)) { FireworkController.Launch(FireworkController.LaunchType.Single); } else if (Input.GetKeyUp(KeyCode.Alpha2)) { FireworkController.Launch(FireworkController.LaunchType.Dud); } else if (Input.GetKeyUp(KeyCode.Alpha3)) { FireworkController.Launch(FireworkController.LaunchType.Finale); } else if (Input.GetKeyUp(KeyCode.Alpha4)) { FireworkController.Launch(FireworkController.LaunchType.Fuse); } #endif // Time to launch! float e = Time.realtimeSinceStartup; if (mLaunchTime > 0.0f && e - mLaunchTime > launchDelay) { switch (mType) { case LaunchType.Dud: // Fire the dud if (dudPrefab != null) { ARScene.Append(dudPrefab); } break; case LaunchType.Finale: // Record the original delay values mFinaleMaxDelay = finaleMaxDelay; mFinaleMinDelay = finaleMinDelay; // Choose a random number of fireworks and start the finale mFinaleCount = finaleMinCount + (int)(Random.value * Mathf.Abs((float)finaleMaxCount - (float)finaleMinCount)); mFinaleStartTime = Time.realtimeSinceStartup; break; case LaunchType.Fuse: // Start the fuse animation ARScene.Append(fusePrefab); break; case LaunchType.Single: // Shoot off a firework ARScene.Append(fireworkPrefab); break; } // Ready for next launch mLaunchTime = 0.0f; mType = LaunchType.None; } // Grand finale timing logic if (mFinaleStartTime > 0.0f && e - mFinaleStartTime > mFinaleDelay) { Launch(LaunchType.Single); mFinaleDelay = finaleMinDelay + Random.value * (Mathf.Abs(finaleMaxDelay - finaleMinDelay)); finaleMaxDelay *= finaleDelayDecay; finaleMinDelay *= finaleDelayDecay; mFinaleStartTime = e; --mFinaleCount; } // Restore delay values when the finale is complete if (mFinaleCount <= 0) { finaleMaxDelay = mFinaleMaxDelay; finaleMinDelay = mFinaleMinDelay; mFinaleStartTime = 0.0f; } }
private void Update() { List <ARPlaneAnchorGameObject> arpags = mUnityARAnchorManager.GetCurrentPlaneAnchors(); if (arpags != null) { // This routine maps the scene to plane anchor, centering // it around a touch point if (UnityARSessionNativeInterface.GetARSessionNativeInterface() != null && Input.touchCount > 0) { // Get the screen location of the touch Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Ended && Camera.main != null) { Vector3 screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // Hit test the plane anchor with the touch point List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane); if (hitResults != null) { foreach (ARHitTestResult i in hitResults) { // We have a hit if (i.isValid) { // Position the AR scene on the plane anchor where // the touch point projects into it Vector3 p = UnityARMatrixOps.GetPosition(i.worldTransform); ARScene.SetPosition(p); // If this is the first time setting up the scene, we'll also // rotate and scale it to fit the orientation and size of // the plane anchor. Subsequent touches will only move // the scene for easy re-centering. if (!ARScene.isVisible) { Quaternion r = UnityARMatrixOps.GetRotation(i.worldTransform); r *= UnityARMatrixOps.GetRotation(i.localTransform); ARScene.SetRotation(r); string id = i.anchorIdentifier; if (id.Length > 0) { foreach (ARPlaneAnchorGameObject arpag in arpags) { if (arpag != null && arpag.planeAnchor.identifier == id) { Vector3 s = arpag.planeAnchor.extent; float d = s.x > s.z ? s.z : s.x; s = new Vector3(d, d, d); ARScene.SetScale(s); break; } } } } // Show the scene ARScene.Show(); break; } } } } } // Hide anchors when scene is visible foreach (ARPlaneAnchorGameObject arpag in arpags) { if (arpag != null && arpag.gameObject != null) { foreach (Renderer r in arpag.gameObject.GetComponentsInChildren <Renderer>()) { r.enabled = !ARScene.isVisible; } } } } }