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

Is there a way to implement mouse interaction in Thebes scenes ? #13

Open
RenuSolanki opened this issue Dec 23, 2022 · 5 comments
Open

Comments

@RenuSolanki
Copy link

RenuSolanki commented Dec 23, 2022

I am willing to use Thebes in one of my own projects. However, I need interactive scenes which can be rotated using mouse just like in MeshCat for example. Is there a way to achieve this in Thebes ?

@cormullion
Copy link
Owner

cormullion commented Dec 23, 2022

Hi there! Unfortunately there's no interactivity 😂 - in my view Thebes is not really a good base to build on - I'd recommend Makie.jl for proper 3D and interaction.

@RenuSolanki
Copy link
Author

Makie provides interactivity but for 3D animations I find Thebes comparatively more intuitive to use. Moreover, Makie has an annoyingly large first time compilation issue.

@cormullion
Copy link
Owner

I’m happy it’s useful - I’ve always seen it as a learning exercise rather than anything else.

I did do this once:

https://plutocon2021-demos.netlify.app/cormullion%20—%202%C2%BD%20d%20graphics

which was fun but not much more than that. 😄

@RenuSolanki
Copy link
Author

With help from a friend I have implemented partial mouse interaction. The following code does only z rotation when mouse moves horizontally. I am not sure how to correctly transform the eyepoint for vertical mouse movement. Zoom effect is also to be implemented.

using WebIO, Thebes, Luxor, Interact, JSExpr

function drawcube(x,y,z,p)
    d=Drawing(800, 800, :svg)
    origin()
    Thebes.background("black")
    helloworld()
    eyepoint(x,y,z)
    perspective(p)
    object = make(Thebes.Cube, "cube")
    scaleby!(object, 80, 80, 80)
    pin(object)
    axes3D(300)
    finish()
    d
end

scope = Scope()
pagex = Observable(scope, "pagex", 0.0)
isdown = Observable(scope, "isdown", 0)
motionx = Observable(scope, "motionx", 0.0)
pagey = Observable(scope, "pagey", 0.0)
motiony = Observable(scope, "motiony", 0.0)
zoom = Observable(scope, "zoom", 0.0)
xe = Observable(300.0)
ye = Observable(0.001)
ze = Observable(0.001)
po = Observable(400.0)
valsx = [0.0]
valsy = [0.0]
on(motionx) do dx
    if isdown[]==1
        l,m,n=rotateby(Point3D(xe[],ye[],ze[]),0.0,0.0,-dx*0.02)
        xe[],ye[],ze[]=l,m,n
    end
end

img = Interact.@map drawcube(&xe, &ye, &ze, &po)

scnd = scope(Node(:div, img, events = Dict(
            "mousedown" => (@js (e) -> (e.preventDefault();$isdown[]=1;$pagex[]=e.clientX;$pagey[]=e.clientY)),
            "mousemove" => (@js (e) -> (e.preventDefault();$motionx[]= (e.clientX-$pagex[]);$motiony[]= ($pagey[]-e.clientY);$pagex[]=e.clientX;$pagey[]=e.clientY)),   
        "mouseup" => (@js (e)-> (e.preventDefault();$isdown[]=0;$motionx[]=e.clientX-$pagex[];$motiony[]=-e.clientY+$pagey[])),
            "wheel"=>(@js (e)-> (e.preventDefault();$zoom[] = e.deltaY))
        )    
    )
)

@cormullion
Copy link
Owner

Cool stuff!

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