Example #1
0
        static void OnDeleteThis(int serialNumber)
        {
            TextureEvaluator eval = FromSerialNumber(serialNumber);

            if (eval != null)
            {
                eval.m_pRhRdkTextureEvaluator = IntPtr.Zero;
            }
        }
Example #2
0
 /// <summary>
 /// Constructs a texture evaluator. This is an independent lightweight object
 /// capable of evaluating texture color throughout uvw space. May be called
 /// from within a rendering shade pipeline.
 /// </summary>
 /// <returns>A texture evaluator instance.</returns>
 public virtual TextureEvaluator CreateEvaluator()
 {
   if (IsNativeWrapper())
   {
     IntPtr pConstThis = ConstPointer();
     IntPtr pTE = UnsafeNativeMethods.Rdk_RenderTexture_NewTextureEvaluator(pConstThis);
     if (pTE != IntPtr.Zero)
     {
       TextureEvaluator te = new TextureEvaluator(pTE);
       return te;
     }
   }
   return null;
 }
Example #3
0
 /// <summary>
 /// Constructs a texture evaluator. This is an independent lightweight object
 /// capable of evaluating texture color throughout uvw space. May be called
 /// from within a rendering shade pipeline.
 /// </summary>
 /// <returns>A texture evaluator instance.</returns>
 public virtual TextureEvaluator CreateEvaluator()
 {
     if (IsNativeWrapper())
     {
         IntPtr ptr_const_this        = ConstPointer();
         IntPtr ptr_texture_evaluator = UnsafeNativeMethods.Rdk_RenderTexture_NewTextureEvaluator(ptr_const_this);
         if (ptr_texture_evaluator != IntPtr.Zero)
         {
             TextureEvaluator te = new TextureEvaluator(ptr_texture_evaluator);
             return(te);
         }
     }
     return(null);
 }
Example #4
0
        static TextureEvaluator FromSerialNumber(int serialNumber)
        {
            int index = serialNumber - 1;

            if (index >= 0 && index < m_all_custom_evaluators.Count)
            {
                TextureEvaluator rc = m_all_custom_evaluators[index];
                if (rc != null && rc.m_runtime_serial_number == serialNumber)
                {
                    return(rc);
                }
            }
            return(null);
        }
Example #5
0
        static int OnGetColor(int serialNumber, Point3d uvw, Vector3d duvwdx, Vector3d duvwdy, ref Display.Color4f color)
        {
            int rc = 0;
            TextureEvaluator eval = FromSerialNumber(serialNumber);

            if (eval != null)
            {
                Display.Color4f c = eval.GetColor(uvw, duvwdx, duvwdy);
                if (c != Display.Color4f.Empty)
                {
                    color = c;
                    rc    = 1;
                }
            }
            return(rc);
        }
Example #6
0
        static IntPtr OnNewTextureEvaluator(int serialNumber)
        {
            IntPtr rc = IntPtr.Zero;

            try
            {
                RenderTexture texture = FromSerialNumber(serialNumber) as RenderTexture;
                if (texture != null)
                {
                    TextureEvaluator eval = texture.CreateEvaluator();
                    if (eval != null)
                    {
                        rc = eval.NonConstPointer();
                    }
                }
            }
            catch
            {
                rc = IntPtr.Zero;
            }
            return(rc);
        }
Example #7
0
        private static FloatBitmap RetrieveFloatsImg(uint rId, int pwidth, int pheight, TextureEvaluator textureEvaluator, bool isEnv, bool planarProjection, bool isLinear)
        {
            var read = FloatImagesNew.ContainsKey(rId);
            var img = read ? FloatImagesNew[rId] : new FloatBitmap(rId, ReadFloatBitmapFromEvaluator(pwidth, pheight, textureEvaluator, isEnv, planarProjection), pwidth, pheight, isLinear);
            if (!read)
            {
                if(RcCore.It.EngineSettings.SaveDebugImages) img.SaveBitmaps();
                FloatImagesNew[rId] = img;
            }

            return img;
        }
Example #8
0
        /// <summary>
        /// Read image as float array from texture evaluator.
        /// </summary>
        /// <param name="pwidth"></param>
        /// <param name="pheight"></param>
        /// <param name="textureEvaluator"></param>
        /// <param name="isEnvironment"></param>
        /// <param name="planarProjection"></param>
        /// <returns></returns>
        private static float[] ReadFloatBitmapFromEvaluator(int pwidth, int pheight, TextureEvaluator textureEvaluator, bool isEnvironment, bool planarProjection)
        {
            var fpixel = new float[pwidth*pheight*4];
            var halfpixelU = 0.5 / pwidth;
            var halfpixelV = 0.5 / pheight;
            var duvw = new Vector3d(halfpixelU, halfpixelV, 0.0);

            for (var x = 0; x < pwidth; x++)
            {
                for (var y = 0; y < pheight; y++)
                {
                    var fx = x/(float) pwidth + halfpixelU;
                    if (isEnvironment && !planarProjection) fx += 0.5f;
                    var fy = y/(float) pheight + halfpixelV;
                    if (planarProjection) fy = 1.0f - fy;

                    // remember z can be !0.0 for volumetrics
                    var col4F = textureEvaluator.GetColor(new Point3d(fx, fy, 0.0), duvw, duvw);
                    var offset = x*4 + pwidth*y*4;
                    fpixel[offset] = col4F.R;
                    fpixel[offset + 1] = col4F.G;
                    fpixel[offset + 2] = col4F.B;
                    fpixel[offset + 3] = col4F.A;
                }
            }
            return fpixel;
        }
Example #9
0
        private static void InternalMaterialBitmapFromEvaluator(CyclesShader shader, RenderTexture renderTexture,
			RenderMaterial.StandardChildSlots textureType, Rhino.Geometry.Transform rhinotfm, uint rId, TextureEvaluator actualEvaluator,
			TextureProjectionMode projectionMode, TextureEnvironmentMappingMode envProjectionMode)
        {
            int pheight;
            int pwidth;
            try
            {
                int u, v, w;
                renderTexture.PixelSize(out u, out v, out w);
                pheight = u;
                pwidth = v;
            }
            catch (Exception)
            {
                pheight = 1024;
                pwidth = 1024;
            }

            if (pheight == 0 || pwidth == 0)
            {
                pheight = 1024;
                pwidth = 1024;
            }

            Transform t = new Transform(
                rhinotfm.ToFloatArray(true)
                );

            var isFloat = renderTexture.IsHdrCapable();
            var isLinear = renderTexture.IsLinear();

            if (isFloat)
            {
                var img = RetrieveFloatsImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                    case RenderMaterial.StandardChildSlots.Diffuse:
                        shader.DiffuseTexture.IsLinear = isLinear;
                        shader.DiffuseTexture.TexFloat = img.Data;
                        shader.DiffuseTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Bump:
                        shader.BumpTexture.IsLinear = isLinear;
                        shader.BumpTexture.TexFloat = img.Data;
                        shader.BumpTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Transparency:
                        shader.TransparencyTexture.IsLinear = isLinear;
                        shader.TransparencyTexture.TexFloat = img.Data;
                        shader.TransparencyTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Environment:
                        shader.EnvironmentTexture.IsLinear = isLinear;
                        shader.EnvironmentTexture.TexFloat = img.Data;
                        shader.EnvironmentTexture.TexByte = null;
                        break;
                }
            }
            else
            {
                var img = RetrieveBytesImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                    case RenderMaterial.StandardChildSlots.Diffuse:
                        shader.DiffuseTexture.IsLinear = isLinear;
                        shader.DiffuseTexture.TexFloat = null;
                        shader.DiffuseTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Bump:
                        shader.BumpTexture.IsLinear = isLinear;
                        shader.BumpTexture.TexFloat = null;
                        shader.BumpTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Transparency:
                        shader.TransparencyTexture.IsLinear = isLinear;
                        shader.TransparencyTexture.TexFloat = null;
                        shader.TransparencyTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Environment:
                        shader.EnvironmentTexture.IsLinear = isLinear;
                        shader.EnvironmentTexture.TexFloat = null;
                        shader.EnvironmentTexture.TexByte = img.Data;
                        break;
                }
            }
            switch (textureType)
            {
                case RenderMaterial.StandardChildSlots.Diffuse:
                    shader.DiffuseTexture.TexWidth = pwidth;
                    shader.DiffuseTexture.TexHeight = pheight;
                    shader.DiffuseTexture.ProjectionMode = projectionMode;
                    shader.DiffuseTexture.EnvProjectionMode = envProjectionMode;
                    shader.DiffuseTexture.Transform = t;
                    shader.DiffuseTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Bump:
                    shader.BumpTexture.TexWidth = pwidth;
                    shader.BumpTexture.TexHeight = pheight;
                    shader.BumpTexture.ProjectionMode = projectionMode;
                    shader.BumpTexture.EnvProjectionMode = envProjectionMode;
                    shader.BumpTexture.Transform = t;
                    shader.BumpTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Transparency:
                    shader.TransparencyTexture.TexWidth = pwidth;
                    shader.TransparencyTexture.TexHeight = pheight;
                    shader.TransparencyTexture.ProjectionMode = projectionMode;
                    shader.TransparencyTexture.EnvProjectionMode = envProjectionMode;
                    shader.TransparencyTexture.Transform = t;
                    shader.TransparencyTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Environment:
                    shader.EnvironmentTexture.TexWidth = pwidth;
                    shader.EnvironmentTexture.TexHeight = pheight;
                    // special texture, always set to Environment/Emap
                    shader.EnvironmentTexture.ProjectionMode = TextureProjectionMode.EnvironmentMap;
                    shader.EnvironmentTexture.EnvProjectionMode = TextureEnvironmentMappingMode.EnvironmentMap;
                    shader.EnvironmentTexture.Transform = t;
                    shader.EnvironmentTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
            }
        }