예제 #1
0
        public static void render(AXParametricObject po, bool makeTexture = false)
        {
            AXModel model = po.model;

            if (model == null)
            {
                return;
            }

            model.assertThumnailSupport();


            // THUMBNAIL BACKGROUND COLOR
            if (po.generator != null && makeTexture)
            {
                model.thumbnailCamera.backgroundColor = po.generator.ThumbnailColor;
            }

            // WHY ARE THE THUMNAIL AND RenTex null?

            if (po.renTex == null)
            {
                po.renTex = new RenderTexture(256, 256, 24);
            }

            if (!po.renTex.IsCreated())
            {
                po.renTex.antiAliasing = 8;
                po.renTex.Create();
            }

            // This started giving an error in 5.3 and did not seem to be needed anyway!

            if (makeTexture)
            {
                RenderTexture.active = po.renTex;
            }

            model.thumbnailCamera.targetTexture = po.renTex;



            model.thumbnailCameraGO.transform.position = po.getThumbnailCameraPosition();
            model.thumbnailCameraGO.gameObject.transform.LookAt(po.getThumbnailCameraTarget());



            // USE THIS MATRIX TO DRAW THE PO's MESHES SOMEWHERE FAR, FAR AWAY


            //Debug.Log("RENDER: " + po.Name);

            Material tmpMat = null;

            if (po.generator is MaterialTool)
            {
                if (po.axMat != null && po.axMat.mat != null)
                {
                    tmpMat = po.axMat.mat;
                }
                else if (po.grouper != null && po.grouper.axMat != null && po.grouper.axMat.mat != null)
                {
                    tmpMat = po.grouper.axMat.mat;
                }
                else
                {
                    tmpMat = model.axMat.mat;
                }

                //Debug.Log("RENDER TEXTURETOOL " + model.thumbnailCameraGO.transform.position + " mesh-> " + model.thumbnailMaterialMesh.vertices.Length + " -- " + tmpMat);

                Graphics.DrawMesh(model.thumbnailMaterialMesh, model.remoteThumbnailLocation, tmpMat, 0, model.thumbnailCamera);

                model.thumbnailCamera.Render();
            }
            else
            {
                AXParameter op = po.getParameter("Output Mesh");
                if (op != null)
                {
                    // RE-RENDER
                    // After a save or reload, the RenterTextures are empty
                    if (op.meshes != null)
                    {
                        for (int mi = 0; mi < op.meshes.Count; mi++)
                        {
                            AXMesh axmesh = op.meshes [mi];
                            if (axmesh.mat != null)
                            {
                                tmpMat = axmesh.mat;
                            }
                            else
                            if (po.axMat != null && po.axMat.mat != null)
                            {
                                tmpMat = po.axMat.mat;
                            }
                            else if (po.grouper != null && po.grouper.axMat != null && po.grouper.axMat.mat != null)
                            {
                                tmpMat = po.grouper.axMat.mat;
                            }

                            else
                            {
                                tmpMat = model.axMat.mat;
                            }


                            Graphics.DrawMesh(axmesh.drawMesh, (model.remoteThumbnailLocation * axmesh.transMatrix), tmpMat, 0, model.thumbnailCamera);
                        }
                    }

                    model.thumbnailCamera.Render();
                }
            }

            // write to texture
            if (makeTexture)
            {
                if (po.thumbnail == null)
                {
                    po.thumbnail = new Texture2D(256, 256);
                }

                po.thumbnail.ReadPixels(new Rect(0, 0, po.renTex.width, po.renTex.height), 0, 0);
                po.thumbnail.Apply();
            }
            if (makeTexture)
            {
                RenderTexture.active = null;
            }

            // 3. Set helper objects to inactive
            model.thumbnailLightGO.SetActive(false);
            model.thumbnailCameraGO.SetActive(false);
        }