Пример #1
0
        public TriangleMeshLight(LightMaterial mt, RayEngineScene scene, TriangleMeshInfo mesh) : base(mt)
        {
            this.scene = scene;
            this.mesh = mesh;
            this.rnd = new FastRandom();

            triangleSampleData = new TriangleSample[this.mesh.TrianglesCount];

            for (int i = mesh.StartTriangle, j = 0; i < mesh.EndTriangle; i++, j++)
            {
                triangleSampleData[j] = new TriangleSample(scene.Triangles[i].AreaV(scene.Vertices), NormalModifier * scene.Triangles[i].ComputeNormal(scene.Vertices));
            }

            triangleSampleData.PartialSort((a, b) => a.Item1.CompareTo(a.Item1), 0, triangleSampleData.Length);

        }
Пример #2
0
        public void Initialize(IRayEngineScene scen, params object[] data)
        {
            zeroSpectra = GlobalConfiguration.Instance.SpectralRendering
                            ? (ISpectrum)ZeroCSpectrumArray
                            : this.RgbSpectrumZeroArray;
            var scn = (RayEngineScene)scen;
            if (mesh == null && !string.IsNullOrWhiteSpace(MeshName))
            {

                this.mesh =
                    scn.Meshes.FirstOrDefault(
                        item => item.MeshName.Equals(MeshName, StringComparison.CurrentCultureIgnoreCase));
                if (this.mesh != null)
                {
                    if (this.mesh.MeshProfile == null)
                    {
                        this.mesh.MeshProfile = new LightsourceProfile()
                        {
                            Light = this
                        };
                    }
                    else
                    {
                        var lightsourceProfile = this.mesh.MeshProfile as LightsourceProfile;
                        if (lightsourceProfile != null)
                            lightsourceProfile.Light = this;
                    }
                    meshMeshArea = 0;
                    for (int i = mesh.StartTriangle; i < mesh.EndTriangle; i++)
                    {
                        meshMeshArea += scn.Triangles[i].AreaV(scn.Vertices);
                    }
                }
            }


            if (mesh == null)
            {
                throw new ArgumentException("Cant find light mesh", this.LightName ?? this.MeshName);
            }

            triangleSampleData = new TriangleSample[this.mesh.TrianglesCount];
            this.scene = scn;

            for (int i = mesh.StartTriangle, j = 0; i < mesh.EndTriangle; i++, j++)
            {
                triangleSampleData[j] = new TriangleSample(scene.Triangles[i].AreaV(scene.Vertices), NormalModifier * scene.Triangles[i].ComputeNormal(scene.Vertices));
            }

            triangleSampleData.PartialSort((a, b) => a.Item1.CompareTo(a.Item1), 0, triangleSampleData.Length);

            if (gain.IsBlack() || infoGain == null)
            {
                gain = scn.DefaultLightGain;
                infoGain = new RgbSpectrumInfo(gain);
            }
            lightSpectra = GlobalConfiguration.Instance.SpectralRendering ? spectra.ToArray() : gain.ToArray();
        }