capnmidnight/Primrose

Ground position update in BrowserEnvironment class should be moved to its own method in the Ground class.

Closed this issue · 5 comments

In the BrowserEnvironment class, in the moveGround function, there are a few lines of code for making sure the ground moves infinitely with the user. The ground plane is a repetitively textured object and it is moved in whole units of the user's position. If you move only a little bit, the ground doesn't move. If you move more than 1 unit in any direction, then the ground is moved a whole unit. Because of the repetitive texture on the ground and the snapped movement of the ground, the user doesn't see the movement.

These lines should be moved to the Ground class, as part of a new method named moveTo. The method should take a single parameter named position. The code should be adapted to use that parameter instead of this.input.head.position. Put the method at the end of the class, before the last curly brace in the file.

Insert a call to this.ground.moveTo(this.input.head.position); in place of the lines at L345-L348 in BrowserEnvironment.

Progress:

  • create moveTo(position) method in Ground class
  • copy code from moveGround function in BrowserEnvironment class to moveTo method in Ground class.
  • replace code in moveGround function with call to this.ground.moveTo(this.input.head.position);
hur commented

I have some questions regarding inheritance and extends. If you have time to answer these, it'd be really helpful.

I spent a good hour looking around in the source code and couldn't find any instance of Groundextending BrowserEnvironment or other forms of inheritance. I'd appreciate if you could point out where this happens or why/how this.ground.moveTo(this.input.head.position); will work in the BrowserEnvironment class.

Another question is regarding three.js files.

'BrowserEnvironment' extends EventDispatcher which is imported from /three/src/core/* however, I couldn't find this folder or the files anywhere. What am I missing here?

I'm not yet very used to reading other peoples' code, so pardon me if I am missing something obvious.

Hi there. Just stopping in to say I saw your reply. I'm on baby duty right now, so can't answer your question, but I will definitely answer tomorrow.

On your first question:

You are correct, Ground does not extend BrowserEnvironment.

Let's start with understanding BrowserEnvironment. The idea with Primrose is that Primrose would provide the equivalent of your PC's desktop, in VR. You as the developer then create objects that react to interactions that define your business logic, and they are grouped together to define your application.

Some objects automatically get added to BrowserEnvironment, like the clock in the corner, the icons on the screen, etc. In the same way that your desktop has a wallpaper that you only have to tell the OS what picture to put there (and not how to draw the picture), BrowserEnvironment provides you a way to tell what to render on the ground (but not how to render it).

So Ground is an object that automatically gets added to the default experience. It's not an extension of BrowserEnvironment. We didn't create a new type of *Environment when we defined the Ground class.

The class is called BrowserEnvironment because one day there might be an AltspaceVREnvironment, or a JanusVREnvironment, or a HighFidelityEnvironment. They all provide that concept of a "default space" and a means on which to define objects that react to your interactions. Implementing such an "AltspaceVREnvironment" would be about defining mappings between the API that AltspaceVR provides for creating objects and object interactions, and how scripts built expecting a Primrose Environment use such objects and interaction to define applications.

On your second question:

EventDispatcher is a class defined in Three.js. The file that Primrose references to load that module is in node_modules/three/src/core. When you import a file, if there is no ./ or ../ at the beginning of it, it is assumed to start looking in the node_modules directory, not relative to the current file. You use ./ at the beginning to make the look up relative to the current file, and you use ../ (or sequences of it) to go up a directory before specifying your import path.

hur commented

Thanks for the in-depth response, that was very helpful!

Also, I went back to browsing code and noticed this line in BrowserEnvironment this.ground = new Ground(this.options).addTo(this.scene);
That seems to be the line that I was missing - makes sense now!

I've updated description of this issue, because I had to move some code around to get the build working again after merging a different PR. I hadn't tested the PR correctly. The changes I made have made this issue a little easier to fix.