Beispiel #1
0
    void drawMesh(GameObject rObject)
    {
//		Debug.Log("Draw Mesh");

        LumarcaMeshRender[] lumarcaMeshes = rObject.GetComponentsInChildren <LumarcaMeshRender>();

        int checkNum = 0;

        Vector3 vec = new Vector3(front[0].x * 10, 0, 0);

        for (int g = 0; g < lumarcaMeshes.Length; g++)
        {
            LumarcaMeshRender lmh = lumarcaMeshes[g];
//			Mesh mesh = filter.sharedMesh;

            GameObject gObject = lmh.gameObject;

            BoxCollider boxCollider = lmh.GetComponent <BoxCollider>();

            verts   = lmh.GetComponent <LumarcaMeshRender>().transformedVerts;
            normals = lmh.GetComponent <LumarcaMeshRender>().transformedNormals;

            bool fast = lmh.GetComponent <LumarcaMeshRender>().fastLessAccurate;

            tris = lmh.mesh.triangles;

            Material rMat = mat;

            if (lmh != null)
            {
                rMat = lmh.material;
            }

            foreach (int zVal in dotsByZY.Keys)
            {
//				Debug.Log("zVal: " + zVal);

                Dictionary <int, List <Vector3> > dict = dotsByZY[zVal];
                foreach (int yVal in dict.Keys)
                {
                    List <Vector3> lineDots = dotsByZY[zVal][yVal];
                    for (int ldNum = 0; ldNum < lineDots.Count; ldNum++)
                    {
                        quadsByZY[zVal][yVal][ldNum].SetActive(false);
                    }

//					Debug.Log("yVal: " + yVal);

                    vec.y = yVal;
                    vec.z = zVal;

                    float x1, x2 = 0;

                    if (PositionInBox2(boxCollider, gObject.transform.lossyScale, gObject.transform.position, vec))
                    {
//						Debug.Log("in box");

                        List <float> intersections;
                        if (!fast)
                        {
                            intersections = GetIntersectList(vec);
                        }
                        else
                        {
                            intersections = GetIntersectListFast(vec);
                        }

                        checkNum++;

                        intersections.Sort();

                        for (int i = 0; i < intersections.Count; i += 2)
                        {
                            if (i + 1 >= intersections.Count)
                            {
                                if (debugMessages)
                                {
                                    Debug.Log("UNEVEN!!! " + intersections.Count);
                                }
                                break;
                            }
                            else
                            {
                                x1 = intersections[i];
                                x2 = intersections[i + 1];
                            }

                            if (x1 > front[1].x)
                            {
                                x1 = front[1].x;
                            }

                            if (x2 > front[1].x)
                            {
                                x2 = front[1].x;
                            }

                            if (x1 < front[0].x)
                            {
                                x1 = front[0].x;
                            }

                            if (x2 < front[0].x)
                            {
                                x2 = front[0].x;
                            }

                            if (x1 != x2)
                            {
                                for (int ldNum = 0; ldNum < lineDots.Count; ldNum++)
                                {
                                    Vector3 lineDot = lineDots[ldNum];

                                    if (lineDot.x >= x1 && lineDot.x <= x2)
                                    {
                                        quadsByZY[zVal][yVal][ldNum].SetActive(true);
                                        quadsByZY[zVal][yVal][ldNum].GetComponent <MeshRenderer>().material = rMat;
                                    }
                                    else if (lineDot.x >= x1 - 50 && lineDot.x <= x2 + 50)
                                    {
                                        quadsByZY[zVal][yVal][ldNum].SetActive(true);
                                        quadsByZY[zVal][yVal][ldNum].GetComponent <MeshRenderer>().material = mat;
                                    }
                                    else
                                    {
//										quadsByZY[zVal][yVal][ldNum].SetActive(false);
                                    }
                                }

//								if(lmh.drawDots){
//									DrawLine(pt1, pt2, rMat);
//								} else {
//									DrawLineWithoutDots(pt1, pt2, rMat);
//								}
                            }
                        }
                    }
                }
            }
        }

//		Debug.Log("checkNum: " + checkNum * mesh.vertexCount/3);
//		Debug.Log("normals: " + mesh.vertices.Length);
//		Debug.Log("tris: " + mesh.normals.Length);
    }
Beispiel #2
0
    void drawMesh(GameObject rObject)
    {
        LumarcaMeshRender[] lumarcaMeshes = rObject.GetComponentsInChildren <LumarcaMeshRender>();

        Vector3 pt1 = new Vector3();
        Vector3 pt2 = new Vector3();

        int checkNum = 0;

        for (int g = 0; g < lumarcaMeshes.Length; g++)
        {
            LumarcaMeshRender lmh = lumarcaMeshes[g];
//			Mesh mesh = filter.sharedMesh;

            GameObject gObject = lmh.gameObject;

            BoxCollider boxCollider = lmh.GetComponent <BoxCollider>();

            verts   = lmh.GetComponent <LumarcaMeshRender>().transformedVerts;
            normals = lmh.GetComponent <LumarcaMeshRender>().transformedNormals;

            bool fast = lmh.GetComponent <LumarcaMeshRender>().fastLessAccurate;

            tris = lmh.mesh.triangles;

            Material rMat = mat;

            if (lmh != null)
            {
                rMat = lmh.material;
            }

            for (int c = 0; c < pos.Length; c++)
            {
                if (!killStringsList.Contains(c))
                {
                    Vector3 vec = pos[c];

                    vec.y = front[2].y * 10;

                    pt1.x = vec.x;
                    pt1.z = vec.z;
                    pt2.x = vec.x;
                    pt2.z = vec.z;

                    if (PositionInBox(boxCollider, gObject.transform.lossyScale, gObject.transform.position, vec))
                    {
                        List <float> intersections;
                        if (!fast)
                        {
                            intersections = GetIntersectList(vec);
                        }
                        else
                        {
                            intersections = GetIntersectListFast(vec);
                        }

                        checkNum++;

                        intersections.Sort();

                        for (int i = 0; i < intersections.Count; i += 2)
                        {
                            if (i + 1 >= intersections.Count)
                            {
                                if (debugMessages)
                                {
                                    Debug.Log("UNEVEN!!! " + intersections.Count);
                                }
                                break;
                            }
                            else
                            {
                                pt1.y = intersections[i];
                                pt2.y = intersections[i + 1];
                            }

                            float lerpPer = (pt1.z - front[0].z) / (back[0].z - front[0].z);

                            float lineHeight = Mathf.Lerp(frontHeight, backHeight, lerpPer);

                            if (cfs.ceilingMounted)
                            {
                                if (pt1.y > front[2].y)
                                {
                                    pt1.y = front[2].y;
                                }

                                if (pt2.y > front[2].y)
                                {
                                    pt2.y = front[2].y;
                                }

                                if (pt1.y < front[2].y - lineHeight)
                                {
                                    pt1.y = front[2].y - lineHeight;
                                }

                                if (pt2.y < front[2].y - lineHeight)
                                {
                                    pt2.y = front[2].y - lineHeight;
                                }
                            }
                            else
                            {
                                if (pt1.y > front[1].y + lineHeight)
                                {
                                    pt1.y = front[1].y + lineHeight;
                                }

                                if (pt2.y > front[1].y + lineHeight)
                                {
                                    pt2.y = front[1].y + lineHeight;
                                }

                                if (pt1.y < front[1].y)
                                {
                                    pt1.y = front[1].y;
                                }

                                if (pt2.y < front[1].y)
                                {
                                    pt2.y = front[1].y;
                                }
                            }

                            if (pt1.y != pt2.y)
                            {
                                if (lmh.drawDots)
                                {
                                    DrawLine(pt1, pt2, rMat);
                                }
                                else
                                {
                                    DrawLineWithoutDots(pt1, pt2, rMat);
                                }
                            }
                        }
                    }
                }
            }
        }

//		Debug.Log("checkNum: " + checkNum * mesh.vertexCount/3);
//		Debug.Log("normals: " + mesh.vertices.Length);
//		Debug.Log("tris: " + mesh.normals.Length);
    }