예제 #1
0
        private static void CreateVertices(List <Segment> segments, int segIndex, float u, GeneratingModel model, List <int> output, out int wrapPoint)
        {
            var seg = segments[segIndex];

            output.Clear();
            for (int i = 0; seg.Rotation0Fraction + seg.RotationStepFraction * i < 1; ++i)
            {
                var frac = seg.Rotation0Fraction + seg.RotationStepFraction * i;
                var pos  = CalculatePosition(seg, frac);
                var rdx  = model.AddRDV(new ModelVertex
                {
                    Position = pos,
                    Normal   = CalculateNormal(segments, segIndex, frac, false),
                    UV       = new Vector2(u, frac),
                });
                output.Add(rdx);
            }
            if (seg.Rotation0Fraction != 0)
            {
                if (output.Count < 2)
                {
                    throw new ArgumentException("Invalid segment");
                }
                var pos = (model.rdv[output[0]].Position + model.rdv[output[output.Count - 1]].Position) / 2;
                var rdx = model.AddRDV(new ModelVertex
                {
                    Position = pos,
                    Normal   = CalculateNormal(segments, segIndex, 0, false),
                    UV       = new Vector2(u, 0),
                });
                output.Add(rdx);
            }
            if (output.Count == 1)
            {
                wrapPoint = -1;

                //Move v to 0.5
                var rtv = model.rdv[output[0]];
                rtv.UV.Y             = 0.5f;
                model.rdv[output[0]] = rtv;
            }
            else
            {
                var zero = output.Where(ii => model.rdv[ii].UV.Y == 0).First();
                var rdx  = model.AddRDV(new ModelVertex
                {
                    Position = model.rdv[zero].Position,
                    Normal   = model.rdv[zero].Normal,
                    UV       = new Vector2(u, 1),
                });
                wrapPoint = rdx;
            }
        }
예제 #2
0
        private static void CloneVertices(List <Segment> segments, int segIndex, GeneratingModel model, List <int> output, ref int wrapPoint)
        {
            var input = output.ToArray();

            output.Clear();
            var  seg           = segments[segIndex];
            bool wrapProcessed = false;

            for (int i = 0; i < input.Length; ++i)
            {
                var rdv = model.rdv[input[i]];
                var deg = seg.Rotation0Fraction + seg.RotationStepFraction * i;
                if (deg >= 1)
                {
                    if (i != input.Length - 1)
                    {
                        continue;                        //should never happen
                    }
                    deg = 0;
                }
                rdv.Normal = CalculateNormal(segments, segIndex, deg, true);
                output.Add(model.AddRDV(rdv));
                if (rdv.UV.Y == 0 && wrapPoint != -1)
                {
                    if (wrapProcessed)
                    {
                        throw new Exception();
                    }
                    var rdv2 = new ModelVertex
                    {
                        Position = model.rdv[wrapPoint].Position,
                        Normal   = rdv.Normal,
                        UV       = model.rdv[wrapPoint].UV,
                    };
                    wrapPoint     = model.AddRDV(rdv2);
                    wrapProcessed = true;
                }
            }

            if (!wrapProcessed && wrapPoint != -1)
            {
                throw new Exception();
            }
        }