How to realize onframe Walking along the Line by js
This article mainly introduces "how to realize the onframe walking along the js". In the daily operation, I believe many people have doubts about how to realize the onframe walking along the js. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize the onframe walking along the js". Next, please follow the editor to study!
The following is a list of a practical application, how to move a model file dynamically online along a well-made line.
Here is the specific js code:
/ / A general function, how to convert the point type of geometry in te into position position
Function pointToPostion (point,altitudeType)
{
Var postionl=SGWorld.Creator.CreatePosition (point.X,point.Y,point.Z,altitudeType,0,0,0,0)
Return postionl
}
/ / define walking model, time and other parameters
Var model = null
Var time
Var linePointCount=0
Var i
Var altitudeType
Var linePoint
Function Init ()
{
ITunes 0
/ / find the pre-drawn line object
Var item = SGWorld.ProjectTree.FindItem ("Line\\ path")
Var poly = SGWorld.ProjectTree.GetObject (item)
/ / get the geometry and height type of the line object, and the points contained in the line
Var polygonGeometry = poly.Geometry
AltitudeType=poly.Position.AltitudeType
LinePoint= polygonGeometry.Points
LinePointCount=polygonGeometry.Points.Count
Var fpos=pointToPostion (linePoint.Item (I), altitudeType)
/ / initialization time and onframe event
Time = new Date ()
SGWorld.AttachEvent ("onFrame", onFrame); / / create a new walking model
Model = SGWorld.Creator.CreateModel (fpos, "D:\\ skylinedata\\ villain .xpl", 3)
}
/ / onframe time implementation, which is the key to the code
Function onFrame ()
{
/ / Walk according to the points in the line, from the first point to the last one. When the point is greater than the number of points, the path is finished.
If (I)