示例#1
0
        private void DrawScene()
        {
            var rect = new Rect(0, 0, this.position.size.x, this.position.size.y);

            this.renderer.camera.nearClipPlane      = 0.1f;
            this.renderer.camera.farClipPlane       = 10000.0f;
            this.renderer.camera.fieldOfView        = cameraFov;
            this.renderer.camera.transform.position = Quaternion.Euler(mouseAction.rotateEuler) * new Vector3(0, 0, -this.mouseAction.zoom);
            this.renderer.camera.transform.rotation = Quaternion.Euler(mouseAction.rotateEuler);
            this.renderer.camera.clearFlags         = CameraClearFlags.SolidColor;

            var mesh         = OctahedralHemiSphere.CreatePrimitive(modelScale, modelMeshes, modelRatio);
            var grid         = OctahedralGrid.CreatePrimitive(10.0f, 100, 10, Color.white * 0.125f, Color.white * 0.25f);
            var gridMaterial = new Material(Shader.Find("OctahedralImposter/Grid"));
            var material     = new Material(Shader.Find("OctahedralImposter/Wireframe"));

            renderer.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 0);
            renderer.DrawMesh(grid, Vector3.zero, Quaternion.identity, gridMaterial, 0);

            this.renderer.BeginPreview(rect, GUIStyle.none);
            this.renderer.camera.Render();
            var tex = this.renderer.EndPreview();

            GameObject.DestroyImmediate(mesh);
            GameObject.DestroyImmediate(grid);

            GUI.DrawTexture(rect, tex);
        }
示例#2
0
        private void Capture()
        {
            var mesh         = OctahedralHemiSphere.CreatePrimitive(modelScale, modelMeshes, modelRatio);
            var meshVertices = mesh.vertices;
            var rect         = new Rect(0, 0, this.position.size.x, this.position.size.y);
            var captures     = modelMeshes + 1;
            var oneSize      = 1.0f / captures;

            int textureResolution = Mathf.FloorToInt(Mathf.Pow(2, this.captureResolution));
            var bgColor           = this.renderer.camera.backgroundColor;

            this.renderer.BeginPreview(new Rect(0f, 0f, textureResolution, textureResolution), GUIStyle.none);

            for (int i = 0; i < meshVertices.Length; ++i)
            {
                var capturePoint  = meshVertices[i];
                var captureLookAt = Quaternion.LookRotation(Vector3.Normalize(this.targetObject.transform.localPosition + captureLookatOffset - capturePoint));

                this.renderer.camera.transform.localPosition = capturePoint;
                this.renderer.camera.transform.localRotation = captureLookAt;

                this.renderer.camera.rect            = new Rect(oneSize * (i % captures), oneSize * (i / captures), oneSize, oneSize);
                this.renderer.camera.backgroundColor = Color.clear;
                this.renderer.camera.Render();
            }

            var tex   = this.renderer.EndPreview();
            var tex2D = ToTexture2D(tex);

            System.IO.File.WriteAllBytes(Application.dataPath + "/OctahedralImposter/capture.png", tex2D.EncodeToPNG());

            this.renderer.camera.backgroundColor = bgColor;
            this.renderer.camera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);

            Debug.Log(Application.dataPath);
            DestroyImmediate(mesh);
            AssetDatabase.Refresh();
        }