/// <summary> /// Returns the UV Parameters for the given Texture. /// This function uses the same operations as in FOpenNurbsTranslatorImpl::TranslateMaterialTable(), improvements should be applied to both functions. /// </summary> /// <param name="RhinoTexture"></param> /// <returns></returns> private static FDatasmithFacadeMaterialsUtils.FUVEditParameters GetUVParameter(Texture RhinoTexture) { // Extract texture mapping info FDatasmithFacadeMaterialsUtils.FUVEditParameters UVParameters = new FDatasmithFacadeMaterialsUtils.FUVEditParameters(); // Use cached texture coordinates(channel 0) UVParameters.SetChannelIndex(0); //// Extract the UV tiling, offset and rotation angle from the UV transform matrix Transform RotationTransform, OrthogonalTransform; Vector3d Translation, Scale; RhinoTexture.UvwTransform.DecomposeAffine(out Translation, out RotationTransform, out OrthogonalTransform, out Scale); double RotX, RotY, RotZ; if (!RotationTransform.GetYawPitchRoll(out RotX, out RotY, out RotZ)) { //This is not a valid rotation make sure the angles are at 0; RotX = RotY = RotZ = 0; } else { RotX = FDatasmithRhinoUtilities.RadianToDegree(RotX); RotY = FDatasmithRhinoUtilities.RadianToDegree(RotY); RotZ = FDatasmithRhinoUtilities.RadianToDegree(RotZ); } UVParameters.SetUVTiling((float)Scale.X, (float)Scale.Y); //If the tiling vector is not zero. if (Math.Abs(Scale.X) > float.Epsilon && Math.Abs(Scale.Y) > float.Epsilon) { float UVOffsetX = (float)(Translation.X / Scale.X); float UVOffsetY = (float)-(Translation.Y / Scale.Y + 0.5f - 0.5f / Scale.Y); UVParameters.SetUVOffset(UVOffsetX, UVOffsetY); // V-coordinate is inverted in Unreal } // Rotation angle is reversed because V-axis points down in Unreal while it points up in OpenNurbs UVParameters.SetRotationAngle((float)-RotX); return(UVParameters); }
private static FDatasmithFacadeActorLight SetupLightActor(RhinoSceneHierarchyNodeInfo HierarchyNodeInfo, Light RhinoLight) { LightObject RhinoLightObject = HierarchyNodeInfo.RhinoModelComponent as LightObject; string HashedName = FDatasmithFacadeElement.GetStringHash(HierarchyNodeInfo.Name); FDatasmithFacadeActorLight LightElement; switch (RhinoLight.LightStyle) { case LightStyle.CameraSpot: case LightStyle.WorldSpot: FDatasmithFacadeSpotLight SpotLightElement = new FDatasmithFacadeSpotLight(HashedName); LightElement = SpotLightElement; double OuterSpotAngle = FDatasmithRhinoUtilities.RadianToDegree(RhinoLight.SpotAngleRadians); double InnerSpotAngle = RhinoLight.HotSpot * OuterSpotAngle; SpotLightElement.SetOuterConeAngle((float)OuterSpotAngle); SpotLightElement.SetInnerConeAngle((float)InnerSpotAngle); break; case LightStyle.WorldLinear: case LightStyle.WorldRectangular: FDatasmithFacadeAreaLight AreaLightElement = new FDatasmithFacadeAreaLight(HashedName); LightElement = AreaLightElement; double Length = RhinoLight.Length.Length; AreaLightElement.SetLength((float)Length); if (RhinoLight.IsRectangularLight) { double Width = RhinoLight.Width.Length; AreaLightElement.SetWidth((float)Width); AreaLightElement.SetLightShape(FDatasmithFacadeAreaLight.EAreaLightShape.Rectangle); AreaLightElement.SetLightType(FDatasmithFacadeAreaLight.EAreaLightType.Rect); } else { AreaLightElement.SetWidth((float)(0.01f * Length)); AreaLightElement.SetLightShape(FDatasmithFacadeAreaLight.EAreaLightShape.Cylinder); AreaLightElement.SetLightType(FDatasmithFacadeAreaLight.EAreaLightType.Point); // The light in Rhino doesn't have attenuation, but the attenuation radius was found by testing in Unreal to obtain a visual similar to Rhino float DocumentScale = (float)Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, UnitSystem.Centimeters); AreaLightElement.SetAttenuationRadius(1800f / DocumentScale); } break; case LightStyle.CameraDirectional: case LightStyle.WorldDirectional: LightElement = new FDatasmithFacadeDirectionalLight(HashedName); break; case LightStyle.CameraPoint: case LightStyle.WorldPoint: LightElement = new FDatasmithFacadePointLight(HashedName); break; case LightStyle.Ambient: // not supported as light default: LightElement = null; break; } if (LightElement != null) { System.Drawing.Color DiffuseColor = RhinoLight.Diffuse; LightElement.SetColor(DiffuseColor.R, DiffuseColor.G, DiffuseColor.B, DiffuseColor.A); LightElement.SetIntensity(RhinoLight.Intensity * 100f); LightElement.SetEnabled(RhinoLight.IsEnabled); LightElement.SetLabel(HierarchyNodeInfo.Label); FDatasmithFacadePointLight PointLightElement = LightElement as FDatasmithFacadePointLight; if (PointLightElement != null) { PointLightElement.SetIntensityUnits(FDatasmithFacadePointLight.EPointLightIntensityUnit.Candelas); } } return(LightElement); }