private Color EvalFlowVolume(Vector3 center, float radius, Cubic <SpanF> modelPos) { float forces = 0.0f; float forceM = 0.0f; float chargeE = 0.008f; float chargeM = 0.014f; Vector3 flowDir = Vector3.zero; var centerQ = spanVectorFromUnity(center, radius); var torqueQ = spanVectorFromUnity(Vector3.zero, 0.0f); float flowVertRadius = 0.04f; float flowVertFwdRadius = 0.02f; var magTorqueCharge = SpanF.exactly(0.021); if (false) { var rv = modelPos.Y.times(SpanF.exactly(2.0)); var rc = SpanAPI.spanColorSignedToRGB(rv); var clr = new Color(rc.X, rc.Y, rc.Z, 0.9f); if (PreviousRY != rv.To) { Debug.Log("M/G: " + rv + " " + rc.Y); PreviousRY = rv.To; } return(clr); } if (true) { foreach (var fv in this.CachedFlowVerts) { var dist = (fv.Location - center).magnitude; var oneOverDistSqr = (1.0f / (dist * dist)); var fe = chargeE * oneOverDistSqr; if (false) { var locQ = spanVectorFromUnity(fv.Location, flowVertRadius); var fQ = spanVectorFromUnity(fv.ForwardDir, flowVertFwdRadius); var rQ = SpanAPI.spanVectorSubtract(centerQ, locQ); var cQ = SpanAPI.spanVectorCross(rQ, fQ); //var cQ = SpanAPI.spanVectorDot(rQ, fQ); var scQ = magTorqueCharge.times(SpanF.exactly(oneOverDistSqr)); cQ = SpanAPI.spanVectorScale(cQ, scQ); torqueQ = SpanAPI.spanVectorAdd(torqueQ, cQ); } var fm = chargeM * oneOverDistSqr * Vector3.Dot(fv.Location - center, -fv.ForwardDir); forces += fe; flowDir += fv.ForwardDir * fe; //forceM += fm; } } if (false) { var torqueMagQ = SpanAPI.spanVectorMagnitude(torqueQ); var rawVal = torqueMagQ; Debug.Log("Val = " + rawVal); //var toColorRangeOffset = SpanAPI.spanExactly (1.0); var toColorRangeScale = SpanAPI.spanExactly(1.0); //var rgb = torqueMagQ.add(toColorRangeOffset).times(toColorRangeScale).ToColorRGB (); var valInRange = rawVal.times(SpanAPI.spanExactly(2.0f / 2.6f)).add(SpanAPI.spanExactly(-1.0f)); var rgb = valInRange.ToColorRGB(); //rgb = new Cubic<float> (0, (float)SpanAPI.spanColorSignedForGreen (valInRange).To, 0); var alpha = rgb.Y; // Mathf.Max(Mathf.Max(rgb.X,rgb.Y),rgb.Z) * 0.5f; return(new Color(rgb.X, rgb.Y, rgb.Z, alpha)); } flowDir.y *= 10.0f; var yval = Mathf.Clamp01(Mathf.Abs(flowDir.normalized.y)); var dirColor = Color.Lerp(this.ColorX, this.ColorY, yval); var clearColor = this.ChakraColor; var fullColor = dirColor; //ColorWithAlpha (dirColor, 1.0f); return(Color.Lerp(clearColor, fullColor, Mathf.Clamp01(forces))); }