/// <summary> /// Complete non-mandatory (deferred) values in the Intersection instance. /// </summary> public void Complete() { if (Solid != null) { // World coordinates. LocalToWorld = Solid.ToWorld(); WorldToLocal = LocalToWorld; WorldToLocal.Invert(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToWorld, out CoordWorld); // Object coordinates. LocalToObject = Solid.ToObject(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToObject, out CoordObject); // Appearance. // Reflectance model. ReflectanceModel = (IReflectanceModel)Solid.GetAttribute(PropertyName.REFLECTANCE_MODEL); if (ReflectanceModel == null) { ReflectanceModel = new PhongModel(); } // Material. Material = (IMaterial)Solid.GetAttribute(PropertyName.MATERIAL); if (Material == null) { Material = ReflectanceModel.DefaultMaterial(); } // Surface color (accepts a color provided by a Solid). if (SurfaceColor == null) { double[] col = (double[])Solid.GetAttribute(PropertyName.COLOR); SurfaceColor = (double[])((col != null) ? col.Clone() : Material.Color.Clone()); } // List of textures. Textures = Solid.GetTextures(); // Solid is responsible for completing remaining values. // Usually: Normal, TextureCoord. Solid.CompleteIntersection(this); Normal.Normalize(); if (Enter != Front) { Vector3d.Multiply(ref Normal, -1.0, out Normal); } } if (SurfaceColor == null) { SurfaceColor = new double[] { 0.0, 0.0, 0.0 } } ; completed = true; }
/// <summary> /// Complete non-mandatory (deferred) values in the Intersection instance. /// </summary> public void Complete() { if (Solid != null) { // world coordinates: LocalToWorld = Solid.ToWorld(); WorldToLocal = LocalToWorld; WorldToLocal.Invert(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToWorld, out CoordWorld); // object coordinates: LocalToObject = Solid.ToObject(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToObject, out CoordObject); // appearance: ReflectanceModel = (IReflectanceModel)Solid.GetAttribute(PropertyName.REFLECTANCE_MODEL); if (ReflectanceModel == null) { ReflectanceModel = new PhongModel(); } Material = (IMaterial)Solid.GetAttribute(PropertyName.MATERIAL); if (Material == null) { Material = ReflectanceModel.DefaultMaterial(); } double[] col = (double[])Solid.GetAttribute(PropertyName.COLOR); SurfaceColor = (double[])((col != null) ? col.Clone() : Material.Color.Clone()); Textures = Solid.GetTextures(); // Solid is responsible for completing remaining values: Solid.CompleteIntersection(this); Normal.Normalize(); if (Enter != Front) { Vector3d.Multiply(ref Normal, -1.0, out Normal); } } if (SurfaceColor == null) { SurfaceColor = new double[] { 0.0, 0.2, 0.3 } } ; completed = true; }
/// <summary> /// Complete non-mandatory (deferred) values in the Intersection instance. /// </summary> public void Complete() { if (Solid != null) { // World coordinates. LocalToWorld = Solid.ToWorld(); WorldToLocal = LocalToWorld; WorldToLocal.Invert(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToWorld, out CoordWorld); // Object coordinates. LocalToObject = Solid.ToObject(); Vector3d.TransformPosition(ref CoordLocal, ref LocalToObject, out CoordObject); // Appearance. // Reflectance model. ReflectanceModel = (IReflectanceModel)Solid.GetAttribute(PropertyName.REFLECTANCE_MODEL); if (ReflectanceModel == null) { ReflectanceModel = new PhongModel(); } // Material. Material = (IMaterial)Solid.GetAttribute(PropertyName.MATERIAL); if (Material == null) { Material = ReflectanceModel.DefaultMaterial(); } // Surface color (accepts a color provided by a Solid). if (SurfaceColor == null) { double[] col = (double[])Solid.GetAttribute(PropertyName.COLOR); SurfaceColor = (double[])((col != null) ? col.Clone() : Material.Color.Clone()); } // List of textures. Textures = Solid.GetTextures(); // Solid is responsible for completing remaining values. // Usually: TangentU, TangentV, NormalLocal, TextureCoord. Solid.CompleteIntersection(this); // Tangent space - NormalLocal, TangentU, TangentV. if (Geometry.IsZeroFast(TangentU.LengthFast)) { // I need NormalLocal if I have no tangent vecotrs. Geometry.GetTangents(ref NormalLocal, out TangentU, out TangentV); } else if (Geometry.IsZeroFast(NormalLocal.LengthFast)) { // I have local tangent vectors but no local normal. Vector3d.Cross(ref TangentU, ref TangentV, out NormalLocal); } // Normal vector: if not computed yet, 'TangentU x TangentV' will do the job. if (Geometry.IsZeroFast(Normal.LengthFast)) { Vector3d tu, tv; tu = Vector3d.TransformVector(TangentU, LocalToWorld); tv = Vector3d.TransformVector(TangentV, LocalToWorld); Vector3d.Cross(ref tu, ref tv, out Normal); } Normal.Normalize(); // to be sure... if (Enter != Front) { Vector3d.Multiply(ref Normal, -1.0, out Normal); } } if (SurfaceColor == null) { SurfaceColor = new double[] { 0.0, 0.0, 0.0 } } ; completed = true; }