Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SceneView touch actions #1

Open
wasdrqm opened this issue Dec 3, 2018 · 5 comments
Open

SceneView touch actions #1

wasdrqm opened this issue Dec 3, 2018 · 5 comments

Comments

@wasdrqm
Copy link

wasdrqm commented Dec 3, 2018

Hi, thank you for article. Can you help me? How i can drag, rotate and scale 3d model without using ArFragment and working via SceneView?

@roshanpatel6040
Copy link

hi @wasdrqm ,
Did you found any solution for scaling and rotation of model in sceneview ?

Help me if you found solution @Hariofspades

@wasdrqm
Copy link
Author

wasdrqm commented Dec 20, 2018

hi @roshanpatel6040, i found solution, but it support only pinches for rotations and scaling.

private lateinit var scene: Scene
private lateinit var transformableNode: TransformableNode
private lateinit var transformationSystem: TransformationSystem

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        transformationSystem = makeTransformationSystem()

        scene = sceneView.scene // get current scene
        scene.addOnUpdateListener {
            if (this::transformableNode.isInitialized) transformableNode.onUpdate(it)
        }
        scene.addOnPeekTouchListener { hitTestResult, motionEvent ->
            if (this::transformationSystem.isInitialized)
                transformationSystem.onTouch(hitTestResult, motionEvent)
        }

        renderObject(Uri.parse("cupcake.sfb")) // Render the object
    }

private fun addNodeToScene(model: ModelRenderable?) {
        val node = Node().apply {
            setParent(scene)
            localPosition = Vector3(0f, -0.3f, -1f)
            localScale = Vector3(2f, 2f, 2f)
            name = "Cupcake"
        }

        transformableNode = TransformableNode(transformationSystem).apply {
            rotationController.isEnabled = true
            scaleController.isEnabled = true
            translationController.isEnabled = false // not support
            renderable = model
            setParent(node)
        }

        scene.onAddChild(node)
        transformableNode.select()
    }

private fun makeTransformationSystem(): TransformationSystem {
        val selectionVisualizer = FootprintSelectionVisualizer()
        val transformationSystem = TransformationSystem(this.resources.displayMetrics, selectionVisualizer)
        (ModelRenderable.builder().setSource(this, com.google.ar.sceneform.ux.R.raw.sceneform_footprint) as com.google.ar.sceneform.rendering.ModelRenderable.Builder).build().thenAccept { renderable ->
            if (selectionVisualizer.footprintRenderable == null) {
                selectionVisualizer.footprintRenderable = renderable
            }

        }.exceptionally {
            Toast.makeText(this, "Unable to load footprint renderable", Toast.LENGTH_SHORT).show()
            null
        }
        return transformationSystem
    }

@roshanpatel6040
Copy link

Hi @wasdrqm ,
It is working perfectly but for the first time when i again try to rotate or manipulate the model it throws exception.
ClassCastException: com.google.ar.sceneform.SceneView cannot be cast to com.google.ar.sceneform.ArSceneView

Thanks for the reply

@roshanpatel6040
Copy link

Hi @wasdrqm
I have one question.
Can we rotate model in all direction irrespective to single axis ?

@wasdrqm
Copy link
Author

wasdrqm commented Dec 21, 2018

Hi @wasdrqm
I have one question.
Can we rotate model in all direction irrespective to single axis ?

hi. I think yes, but you need to write new TransformationController for this action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants