public override void _Process(float delta) { _curTime += IsGlowing ? delta / OnTime : -delta / OffTime; _curTime.Constrain(0, 1); if (_material == null) { return; } var energy = Energy * Mathf.Ease(_curTime, Curve); // GD.Print(energy.ToString()); _material.EmissionEnergy = energy; _light.Visible = _curTime != 0; _light.LightEnergy = energy / 12 + 0.1f; }
public void RenderTrail() { Clear(); Begin(Mesh.PrimitiveType.Triangles); Godot.Collections.Array <Vector3> localPoints = new Godot.Collections.Array <Vector3>(); foreach (Vector3 p in points) { localPoints.Add(p - GlobalTransform.origin); } Vector3 lastP = Vector3.Zero; Godot.Collections.Array <Godot.Collections.Array <Vector3> > verts = new Godot.Collections.Array <Godot.Collections.Array <Vector3> >(); int ind = 0; bool firstIteration = true; Vector3 lastFirstVec = Vector3.Zero; foreach (Vector3 p in localPoints) { Godot.Collections.Array <Vector3> newLastPoints = new Godot.Collections.Array <Vector3>(); var offset = lastP - p; if (offset == Vector3.Zero) { continue; } var yVec = offset.Normalized(); // get vector pointing from this point to last point var xVec = Vector3.Zero; if (firstIteration) { xVec = yVec.Cross(yVec.Rotated(Vector3.Right, 0.3f)); //cross product with random vector to get a perpendicular vector } else { xVec = yVec.Cross(lastFirstVec).Cross(yVec).Normalized(); // keep each loop at the same rotation as the previous } var width = maxRadius; if (shape != 0) { width = (1 - Mathf.Ease((ind + 1.0f) / densityLengthwise, shape)) * maxRadius; } Godot.Collections.Array <Vector3> segVerts = new Godot.Collections.Array <Vector3>(); var fIter = true; for (int i = 0; i < densityAround; i++) // set up row of verts for each level { var newVert = p + width * xVec.Rotated(yVec, i * 2 * Mathf.Pi / densityAround).Normalized(); if (fIter) { lastFirstVec = newVert - p; fIter = false; } segVerts.Add(newVert); } verts.Add(segVerts); lastP = p; ind += 1; firstIteration = false; } for (int j = 0; j < verts.Count - 1; j++) { var cur = verts[j]; var nxt = verts[j + 1]; // 1.0 added to avoid division by zero float uv = (j + 1.0f) / (verts.Count + 1); float uvnxt = (j + 2.0f) / (verts.Count + 1); for (int i = 0; i < densityAround; i++) { var nxtI = (i + 1) % densityAround; //order added affects normal SetUv(new Vector2(uv, 0f)); AddVertex(cur[i]); AddVertex(cur[nxtI]); SetUv(new Vector2(uvnxt, 0f)); AddVertex(nxt[i]); SetUv(new Vector2(uv, 0f)); AddVertex(cur[nxtI]); SetUv(new Vector2(uvnxt, 0f)); AddVertex(nxt[nxtI]); SetUv(new Vector2(uvnxt, 0f)); AddVertex(nxt[i]); } } if (verts.Count > 1) { for (int i = 0; i < densityAround; i++) { var nxt = (i + 1) % densityAround; SetUv(Vector2.Zero); AddVertex(verts[0][i]); AddVertex(Vector3.Zero); AddVertex(verts[0][nxt]); } for (int i = 0; i < densityAround; i++) { var nxt = (i + 1) % densityAround; SetUv(new Vector2(1f, 0f)); AddVertex(verts[verts.Count - 1][i]); AddVertex(verts[verts.Count - 1][nxt]); AddVertex(lastP); } } End(); }
public void RenderTrail() { //Clears all the drawn geometry the imediate draw node has drawn the previous frame Clear(); //Begin the imidiate draw mode with the primative mode paased into it Begin(Mesh.PrimitiveType.Triangles); //A godot array for the Vector3 point called local points Godot.Collections.Array <Vector3> localPoints = new Godot.Collections.Array <Vector3>(); //Loop throuhgt hte points array again foreach (Vector3 p in points) { //We add the points members to the local points array after we subtracted the global transform from the point p localPoints.Add(p - GlobalTransform.origin); } //Create a new last point variable for use int this method Vector3 lastP = Vector3.Zero; //Create a new godot array for the verticies Godot.Collections.Array <Godot.Collections.Array <Vector3> > verts = new Godot.Collections.Array <Godot.Collections.Array <Vector3> >(); int ind = 0; //If its the first interation of the loop below, here we just "reset" the firstInteration bool for use in the loop bool firstIteration = true; //Zero the lastFirstVec value Vector3 lastFirstVec = Vector3.Zero; //Loopthrough the localPoint array foreach (Vector3 p in localPoints) { //New godot array for the new last points Godot.Collections.Array <Vector3> newLastPoints = new Godot.Collections.Array <Vector3>(); //Variable for the offset of the last point with the current point (Vector points from lastP to p) var offset = lastP - p; //If there is no offset if (offset == Vector3.Zero) { //We continue with the code continue; } Vector3 yVec = offset.Normalized(); // get vector pointing from this point to last point //Set het x Vector to zero Vector3 xVec = Vector3.Zero; //If this is the first ineration of the loop (First time the loop is run) if (firstIteration) { xVec = yVec.Cross(yVec.Rotated(Vector3.Right, 0.3f)); //cross product with random vector to get a perpendicular vector } else { xVec = yVec.Cross(lastFirstVec).Cross(yVec).Normalized(); // keep each loop at the same rotation as the previous } var width = maxRadius; if (shape != 0) { width = (1 - Mathf.Ease((ind + 1.0f) / densityLengthwise, shape)) * maxRadius; } Godot.Collections.Array <Vector3> segVerts = new Godot.Collections.Array <Vector3>(); var fIter = true; for (int i = 0; i < densityAround; i++) // set up row of verts for each level { var newVert = p + width * xVec.Rotated(yVec, i * 2 * Mathf.Pi / densityAround).Normalized(); if (fIter) { lastFirstVec = newVert - p; fIter = false; } segVerts.Add(newVert); } verts.Add(segVerts); lastP = p; ind += 1; firstIteration = false; } for (int j = 0; j < verts.Count - 1; j++) { var cur = verts[j]; var nxt = verts[j + 1]; for (int i = 0; i < densityAround; i++) { var nxtI = (i + 1) % densityAround; //order added affects normal AddVertex(cur[i]); AddVertex(cur[nxtI]); AddVertex(nxt[i]); AddVertex(cur[nxtI]); AddVertex(nxt[nxtI]); AddVertex(nxt[i]); } } if (verts.Count > 1) { for (int i = 0; i < densityAround; i++) { var nxt = (i + 1) % densityAround; AddVertex(verts[0][i]); AddVertex(Vector3.Zero); AddVertex(verts[0][nxt]); } for (int i = 0; i < densityAround; i++) { var nxt = (i + 1) % densityAround; AddVertex(verts[verts.Count - 1][i]); AddVertex(verts[verts.Count - 1][nxt]); AddVertex(lastP); } } End(); }