com.google.ar.sceneform.Node Java Examples
The following examples show how to use
com.google.ar.sceneform.Node.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LightingActivity.java From sceneform-samples with Apache License 2.0 | 6 votes |
@SuppressWarnings("FutureReturnValueIgnored") private void addMenuToNode(Node node, Vector3 localPosition) { ViewRenderable.builder() .setView(this, R.layout.material_options_view) .build() .thenAccept( viewRenderable -> { node.setRenderable(viewRenderable); node.setEnabled(false); node.setLocalPosition(localPosition); node.setWorldScale(new Vector3(.65f, .65f, .5f)); setupMaterialMenu(viewRenderable, node); }) .exceptionally( throwable -> { displayError(throwable); throw new CompletionException(throwable); }); }
Example #2
Source File: LightingActivity.java From sceneform-samples with Apache License 2.0 | 6 votes |
private Node createMenuNode(Node node, Vector3 localPosition) { Node menu = new Node(); menu.setParent(node); addMenuToNode(menu, localPosition); node.setOnTapListener( new OnTapListener() { @Override public void onTap(HitTestResult hitTestResult, MotionEvent motionEvent) { menu.setEnabled(!menu.isEnabled()); if (openMenuNode != null) { openMenuNode.setEnabled(false); openMenuNode = (openMenuNode == menu) ? null : menu; } else { openMenuNode = menu; } } }); return menu; }
Example #3
Source File: LocationActivity.java From ARCore-Location with MIT License | 6 votes |
/** * Example node of a layout * * @return */ private Node getExampleView() { Node base = new Node(); base.setRenderable(exampleLayoutRenderable); Context c = this; // Add listeners etc here View eView = exampleLayoutRenderable.getView(); eView.setOnTouchListener((v, event) -> { Toast.makeText( c, "Location marker touched.", Toast.LENGTH_LONG) .show(); return false; }); return base; }
Example #4
Source File: LocationNode.java From ARCore-Location with MIT License | 6 votes |
private boolean isOverlapping(Node n, Ray ray, Vector3 target, Vector3 cameraPosition) { Vector3 nodeDirection = Vector3.subtract(target, cameraPosition); ray.setDirection(nodeDirection); ArrayList<HitTestResult> hitTestResults = locationScene.mArSceneView.getScene().hitTestAll(ray); if (hitTestResults.size() > 0) { HitTestResult closestHit = null; for (HitTestResult hit : hitTestResults) { //Get the closest hit on enabled Node if (hit.getNode() != null && hit.getNode().isEnabled()) { closestHit = hit; break; } } // if closest hit is not the current node, it is hidden behind another node that is closer return closestHit != null && closestHit.getNode() != n; } return false; }
Example #5
Source File: LightingActivity.java From sceneform-samples with Apache License 2.0 | 5 votes |
private void setUpLights() { Light.Builder lightBuilder = Light.builder(Type.POINT) .setFalloffRadius(LIGHT_FALLOFF_RADIUS) .setShadowCastingEnabled(false) .setIntensity(intensityBar.getProgress()); for (int i = 0; i < 4; i++) { // Sets the color of and creates the light. lightBuilder.setColor(ColorConfig.getColor(pointlightColorConfig, i)); Light light = lightBuilder.build(); // Create node and set its light. Vector3 localPosition = new Vector3(-0.4f + (i * .2f), POINTLIGHT_CUBE_HEIGHT_OFFSET_METERS, 0.0f); RotatingNode orbit = new RotatingNode(); orbit.setParent(anchorNode); Node lightNode = new Node(); lightNode.setParent(orbit); lightNode.setLocalPosition(localPosition); lightNode.setLight(light); // Check if lights are currently switched on or off, and update accordingly. lightNode.setEnabled(toggleLights.isChecked()); pointlightNodes.add(lightNode); } isLightingInitialized = true; }
Example #6
Source File: LightingActivity.java From sceneform-samples with Apache License 2.0 | 5 votes |
private Node createShapeNode( AnchorNode anchorNode, ModelRenderable renderable, Vector3 localPosition) { Node shape = new Node(); shape.setParent(anchorNode); shape.setRenderable(renderable); shape.setLocalPosition(localPosition); return shape; }
Example #7
Source File: LocationActivity.java From ARCore-Location with MIT License | 5 votes |
/*** * Example Node of a 3D model * * @return */ private Node getAndy() { Node base = new Node(); base.setRenderable(andyRenderable); Context c = this; base.setOnTapListener((v, event) -> { Toast.makeText( c, "Andy touched.", Toast.LENGTH_LONG) .show(); }); return base; }
Example #8
Source File: LightingActivity.java From sceneform-samples with Apache License 2.0 | 4 votes |
private void changeMaterialValue(String propertyName, float change, Node node) { Material material = node.getParent().getRenderable().getMaterial(); material.setFloat(propertyName, change); }
Example #9
Source File: LocationNode.java From ARCore-Location with MIT License | 4 votes |
@Override public void onUpdate(FrameTime frameTime) { // Typically, getScene() will never return null because onUpdate() is only called when the node // is in the scene. // However, if onUpdate is called explicitly or if the node is removed from the scene on a // different thread during onUpdate, then getScene may be null. for (Node n : getChildren()) { if (getScene() == null) { return; } Vector3 cameraPosition = getScene().getCamera().getWorldPosition(); Vector3 nodePosition = n.getWorldPosition(); // Compute the difference vector between the camera and anchor float dx = cameraPosition.x - nodePosition.x; float dy = cameraPosition.y - nodePosition.y; float dz = cameraPosition.z - nodePosition.z; // Compute the straight-line distance. double distanceInAR = Math.sqrt(dx * dx + dy * dy + dz * dz); setDistanceInAR(distanceInAR); if (locationScene.shouldOffsetOverlapping()) { if (locationScene.mArSceneView.getScene().overlapTestAll(n).size() > 0) { setHeight(getHeight() + 1.2F); } } if (locationScene.shouldRemoveOverlapping()) { Ray ray = new Ray(); ray.setOrigin(cameraPosition); float xDelta = (float) (distanceInAR * Math.sin(Math.PI / 15)); //12 degrees Vector3 cameraLeft = getScene().getCamera().getLeft().normalized(); Vector3 left = Vector3.add(nodePosition, cameraLeft.scaled(xDelta)); Vector3 center = nodePosition; Vector3 right = Vector3.add(nodePosition, cameraLeft.scaled(-xDelta)); boolean isOverlapping = isOverlapping(n, ray, left, cameraPosition) || isOverlapping(n, ray, center, cameraPosition) || isOverlapping(n, ray, right, cameraPosition); if (isOverlapping) { setEnabled(false); } else { setEnabled(true); } } } if (!locationScene.minimalRefreshing()) scaleAndRotate(); if (renderEvent != null) { if (this.isTracking() && this.isActive() && this.isEnabled()) renderEvent.render(this); } }
Example #10
Source File: LocationNode.java From ARCore-Location with MIT License | 4 votes |
public void scaleAndRotate() { for (Node n : getChildren()) { int markerDistance = (int) Math.ceil( LocationUtils.distance( locationMarker.latitude, locationScene.deviceLocation.currentBestLocation.getLatitude(), locationMarker.longitude, locationScene.deviceLocation.currentBestLocation.getLongitude(), 0, 0) ); setDistance(markerDistance); // Limit the distance of the Anchor within the scene. // Prevents uk.co.appoly.arcorelocation.rendering issues. int renderDistance = markerDistance; if (renderDistance > locationScene.getDistanceLimit()) renderDistance = locationScene.getDistanceLimit(); float scale = 1F; final Vector3 cameraPosition = getScene().getCamera().getWorldPosition(); Vector3 direction = Vector3.subtract(cameraPosition, n.getWorldPosition()); switch (scalingMode) { case FIXED_SIZE_ON_SCREEN: scale = (float) Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z); break; case GRADUAL_TO_MAX_RENDER_DISTANCE: float scaleDifference = gradualScalingMaxScale - gradualScalingMinScale; scale = (gradualScalingMinScale + ((locationScene.getDistanceLimit() - markerDistance) * (scaleDifference / locationScene.getDistanceLimit()))) * renderDistance; break; case GRADUAL_FIXED_SIZE: scale = (float) Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z); float gradualScale = gradualScalingMaxScale - gradualScalingMinScale; gradualScale = gradualScalingMaxScale - (gradualScale / renderDistance * markerDistance); scale *= Math.max(gradualScale, gradualScalingMinScale); break; } scale *= scaleModifier; //Log.d("LocationScene", "scale " + scale); n.setWorldPosition(new Vector3(n.getWorldPosition().x, getHeight(), n.getWorldPosition().z)); Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up()); n.setWorldRotation(lookRotation); n.setWorldScale(new Vector3(scale, scale, scale)); } }
Example #11
Source File: LocationMarker.java From ARCore-Location with MIT License | 4 votes |
public LocationMarker(double longitude, double latitude, Node node) { this.longitude = longitude; this.latitude = latitude; this.node = node; }