An advanced Lerping module threejs example
read up more on monotonic functions
One thing that is related to this module would be the topic of monotonic functions. This is mainly true when it comes to making what I am calling a get alpha method to use with the advanced lerp module. The reason why I say that is that the alpha values that I want to return should at least stay the same, if not go up, as the alpha value that i give them goes from 0 to 1. The general idea here is to just find novel and interesting was of how to go about creating alpha values that do not go up in a straight line, linear, or fixed kind of fashion.
Check out the vector3 class in detail
This advanced lerp module involves creating what I am calling get alpha methods that create alpha values that are then used with the Vector3 class lerp method. The Vector3 class itself is worth checking gout in detail if you have not do so before hand as there is a great range of methods to work with when working with an instance of Vector3.
The source code is on Github also
The source code that I am writing about here can also be found in my test threejs repository on github. This is project that I might continue working on for a while so the state of the code here might be a little out of date compared to what I have there between edits of this content that might prove to be few and far between.
Version numbers matter
When I first started this post I was using r140 of threejs
This might prove to be the kind of project where I will end up making at least a few revisions, but not mater what there is always the starting point. So then in this section I will be outlining what I have thus far in the first version ( r0 ) of my advance lerp module. There is going over the state of the module itself, but also taking a look at a number of demos of the module also just for the sake of testing out that the module works okay and that I am getting the kinds of results that I would like to have when using it in some kind of actual project. I have some planes when it comes to the use of this module as a foundation for many additional projects so I would like to try my best to get this fairly solid right away.
1.1 - The ap lerp module
The advanced lerp module returns three public methods as of r0, one of which is the lerp method that works in a similar way to that of the vector3 lerp method but with additional options that can be passed. Another method can be used to create and return an array of vector3 class instances that are between two vectors, which also makes use of the same internal lerp helper function. A final third public method can be used to quickly create a group of mesh objects that use the sphere geometry and normal material as a way to get a sense of what is going on when using the ap lerp method when making a few demos of it.
When it come to using the lerp method or the get points between method I will want to choose a built in get alha method, or write my own. For r0 of this project there are just two built in lerp methods, ‘simp’, and ‘pow1’ the default of which is pow1. The simp built in as the same suggest is just a simple regular lerp which defeats the purpose of using this whole thing kind of, but I figure I will still want to have that as a built in option. Speaking of get alpha methods as the name suggest this is the method that will be used to generate the alpha method that will then in turn be used for the vector3 lerp method. So at the core of this is still th built in threejs lerp method, and all of this additional code is just a kind of framework for creating alpha values for the use of that method.
1.2 - Basic demo of the core features of apLerp
Now that I have my module in a state that is looking good at least I will want to make at least one, if not a few demos of the module just for the sake of making sure that it is working okay. For this first basic demo of the advanced lerp module I am creating a basic scene as always and then testing out the lerp method of the module by just calling it with some vectors and options and just longing the results to the console. When using the simp and pow one method that vectors that are being returned look good, so but I will want to test out the other methods as well here.
So then I am using the create sphere group method that also makes use of the other public method to create a collection of sphere geometries. I use this method to create two groups, one for each built in get alpha method and add them to my scene object. The result is then what I would expect a line of mesh objects where each mesh is an equal distance apart with the simp built in get alpha, and then that not being the case with my pow1 built in method.
1.2 - More on the pow built in get alpha method
I would like to make another demo for r0 of the advanced lerp module where I am creating a collection of groups all using the pow1 built in method. For each group I am then tweaking the parameters that I can give to the pow1 method and for this example I will be tweaking the e parameter rather than the base for each group.
1.3 - A parabola get alpha method prototype
This is another demo in which I am creating a prototype of a get alpha method based off of an expression for creating a parabola. Thus far the get alpha method seems to work okay, but at this time I do not think I will be making this a built in option for any future revisions of this module. Thats okay though as that is the general idea that I have here, tired yet true get aloha methods will be built in, any any experimental get alpha methods will just be demos like this, or get pulled into some kind of optional pliug in.
1.4 - Making a get alpha method with Math.sin
One of the main things about this is that I want to move objects in a way in which they start out slow, then move faster, and then slow down again as they get to the other point. When I use this sin get alpha method with the proper parameters I can get that kind of effect which is cool.
The core idea that I had in mind with this project all ready seems to be working well, I might want to make at least an r1 of it though before I start to use this as a groundwork for additional modules though. When it comes to additional modules built on top of this though I have no shortage of ideas for it, that should go without saying. I am thinking about at lest two projects that have to do with the creation and movement of cameras, and at least one that has to do with mesh objects, but getting into all of that will be a mater of additional future blog posts.