Beispiel #1
0
        protected void AddH2O()
        {
            var angle     = 104.5f;
            var edges     = this.indexData.edgeToAdd.CPUData;
            var edgeCount = 0;
            var vBase     = this.pCount;
            var vcount    = 3;
            var y         = 0.1f;
            var x         = math.tan(angle * 0.5f * Mathf.Deg2Rad) * y;
            var center    = new float3(UnityEngine.Random.value, UnityEngine.Random.value, 0) * 0.01f;
            var rand      = UnityEngine.Random.rotationUniform;
            // rand = Quaternion.Euler(0, 0, UnityEngine.Random.value * 2 * Mathf.PI * Mathf.Rad2Deg);
            var p1 = rand * new Vector3(x, y, 0);
            var p2 = rand * new Vector3(-x, y, 0);

            edges[edgeCount++] = new EdgeToAdd(sid, vBase, vBase + 1, center, center + new float3(p1));
            edges[edgeCount++] = new EdgeToAdd(sid, vBase, vBase + 2, center, center + new float3(p2));
            while (edgeCount < edges.Length)
            {
                edges[edgeCount++] = new EdgeToAdd(-1, -1, -1, 0, 0);
            }

            this.sid++;
            this.pCount += vcount;
            this.dispatcher.Dispatch(Kernel.AddEdge, this.data.edgeCount);
        }
Beispiel #2
0
        protected void AddOneCircle(int sid)
        {
            var edges     = this.indexData.edgeToAdd.CPUData;
            var edgeCount = 0;
            var vBase     = this.pCount;
            var center    = new float3(UnityEngine.Random.value, UnityEngine.Random.value, 0) * 0.01f;
            var cid       = vcount;
            var rand      = UnityEngine.Random.value;
            var circle    = GeometryTools.GenerateCirclePoint(vcount, this.radius);

            foreach (var i in Enumerable.Range(0, vcount))
            {
                var i1 = i;
                var i2 = (i + 1) % vcount;
                edges[edgeCount++] = new EdgeToAdd(sid, i1 + vBase, i2 + vBase, circle[i1] + center, circle[i2] + center);
            }
            if (this.withCenter)
            {
                foreach (var i in Enumerable.Range(0, vcount))
                {
                    edges[edgeCount++] = new EdgeToAdd(sid, i + vBase, cid + vBase, circle[i] + center, center);
                }
                this.pCount += vcount + 1;
            }
            else
            {
                this.pCount += vcount;
            }

            while (edgeCount < edges.Length)
            {
                edges[edgeCount++] = new EdgeToAdd(-1, -1, -1, 0, 0);
            }
        }
Beispiel #3
0
        protected void AddMesh(Mesh m)
        {
            var edgeCount  = 0;
            var edges      = this.indexData.edgeToAdd.CPUData;
            var indexCount = this.pCount;
            var added      = new Dictionary <Vector3, int>();

            for (var t = 0; t < m.triangles.Length; t += 3)
            {
                var v1 = m.vertices[m.triangles[t]];
                var v2 = m.vertices[m.triangles[t + 1]];
                var v3 = m.vertices[m.triangles[t + 2]];

                int p1;
                int p2;
                int p3;
                if (!added.TryGetValue(v1, out p1))
                {
                    p1 = indexCount++;
                    added.Add(v1, p1);
                }
                if (!added.TryGetValue(v2, out p2))
                {
                    p2 = indexCount++;
                    added.Add(v2, p2);
                }
                if (!added.TryGetValue(v3, out p3))
                {
                    p3 = indexCount++;
                    added.Add(v3, p3);
                }

                v1 = this.transform.TransformPoint(v1);
                v2 = this.transform.TransformPoint(v2);
                v3 = this.transform.TransformPoint(v3);

                edges[edgeCount++] = new EdgeToAdd(this.sid, p1, p2, v1, v2);
                edges[edgeCount++] = new EdgeToAdd(this.sid, p2, p3, v2, v3);
                edges[edgeCount++] = new EdgeToAdd(this.sid, p3, p1, v3, v1);
            }
            this.pCount += added.Count;
            this.sid++;

            this.dispatcher.Dispatch(Kernel.AddEdge, this.data.edgeCount);
        }