internal void AddPreviewItem(string bitmap, Curve c, Rectangle3d bounds)
        {
            var            mesh = Mesh.CreateFromPlanarBoundary(c, MeshingParameters.FastRenderMesh, 0.1);
            TextureMapping tm   = TextureMapping.CreatePlaneMapping(bounds.Plane, bounds.X, bounds.Y, new Interval(-1, 1));

            mesh.SetTextureCoordinates(tm, Transform.Identity, true);
            var mat = new DisplayMaterial(System.Drawing.Color.White);

            ///Force bitmap to redraw
            //string docBitmapName = string.Empty;
            //var docBitmap = Rhino.RhinoDoc.ActiveDoc.Bitmaps.Find(bitmap, true, out docBitmapName);
            //mat.SetBitmapTexture(docBitmapName, true);

            mat.SetBitmapTexture(bitmap, true);

            _previewItems.Add(new HeronRasterPreviewItem()
            {
                mesh = mesh,
                mat  = mat
            });

            ///Use Wait to refresh images
            ///https://discourse.mcneel.com/t/wish-list-set-bitmap-texture-from-memory-stream/105158/5
            ///https://mcneel.myjetbrains.com/youtrack/issue/RH-59416
            Rhino.RhinoApp.Wait();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="mapping"></param>
        /// <returns></returns>
        public static Texture LoadTexture(string url, TextureMapping mapping = null)
        {
            var image = (Bitmap)Image.FromFile(url, true);

            image.RotateFlip(RotateFlipType.Rotate180FlipX);

            return(new Texture(image, mapping)
            {
                NeedsUpdate = true, SourceFile = url, Format = ImageLoader.PixelFormatToThree(image.PixelFormat)
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapMode">Texture wrap mode</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, uint texIndex, TextureMapping mapping, uint uvIndex, float blendFactor,
     TextureOperation texOp, TextureWrapMode wrapMode, uint flags)
 {
     _filePath = (filePath == null) ? String.Empty : filePath;
         _type = typeSemantic;
         _index = texIndex;
         _mapping = mapping;
         _uvIndex = uvIndex;
         _blendFactor = blendFactor;
         _texOp = texOp;
         _wrapMode = wrapMode;
         _flags = flags;
 }
        public void Copy(TextGenerationSettings other)
        {
            bool flag = other == null;

            if (!flag)
            {
                this.text                   = other.text;
                this.screenRect             = other.screenRect;
                this.margins                = other.margins;
                this.scale                  = other.scale;
                this.fontAsset              = other.fontAsset;
                this.material               = other.material;
                this.spriteAsset            = other.spriteAsset;
                this.fontStyle              = other.fontStyle;
                this.textAlignment          = other.textAlignment;
                this.overflowMode           = other.overflowMode;
                this.wordWrap               = other.wordWrap;
                this.wordWrappingRatio      = other.wordWrappingRatio;
                this.color                  = other.color;
                this.fontColorGradient      = other.fontColorGradient;
                this.tintSprites            = other.tintSprites;
                this.overrideRichTextColors = other.overrideRichTextColors;
                this.fontSize               = other.fontSize;
                this.autoSize               = other.autoSize;
                this.fontSizeMin            = other.fontSizeMin;
                this.fontSizeMax            = other.fontSizeMax;
                this.enableKerning          = other.enableKerning;
                this.richText               = other.richText;
                this.isRightToLeft          = other.isRightToLeft;
                this.extraPadding           = other.extraPadding;
                this.parseControlCharacters = other.parseControlCharacters;
                this.characterSpacing       = other.characterSpacing;
                this.wordSpacing            = other.wordSpacing;
                this.lineSpacing            = other.lineSpacing;
                this.paragraphSpacing       = other.paragraphSpacing;
                this.lineSpacingMax         = other.lineSpacingMax;
                this.maxVisibleCharacters   = other.maxVisibleCharacters;
                this.maxVisibleWords        = other.maxVisibleWords;
                this.maxVisibleLines        = other.maxVisibleLines;
                this.firstVisibleCharacter  = other.firstVisibleCharacter;
                this.useMaxVisibleDescender = other.useMaxVisibleDescender;
                this.fontWeight             = other.fontWeight;
                this.pageToDisplay          = other.pageToDisplay;
                this.horizontalMapping      = other.horizontalMapping;
                this.verticalMapping        = other.verticalMapping;
                this.uvLineOffset           = other.uvLineOffset;
                this.geometrySortingOrder   = other.geometrySortingOrder;
                this.inverseYAxis           = other.inverseYAxis;
                this.charWidthMaxAdj        = other.charWidthMaxAdj;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapModeU">Texture wrap mode for U coordinate</param>
 /// <param name="wrapModeV">Texture wrap mode for V coordinate</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, int texIndex, TextureMapping mapping, int uvIndex, float blendFactor,
                    TextureOperation texOp, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, int flags)
 {
     FilePath     = (filePath == null) ? String.Empty : filePath;
     TextureType  = typeSemantic;
     TextureIndex = texIndex;
     Mapping      = mapping;
     UVIndex      = uvIndex;
     BlendFactor  = blendFactor;
     Operation    = texOp;
     WrapModeU    = wrapModeU;
     WrapModeV    = wrapModeV;
     Flags        = flags;
 }
Exemplo n.º 6
0
        internal void AddPreviewItem(string bitmap, Curve c, Rectangle3d bounds)
        {
            var            mesh = Mesh.CreateFromPlanarBoundary(c, MeshingParameters.FastRenderMesh, 0.1);
            TextureMapping tm   = TextureMapping.CreatePlaneMapping(bounds.Plane, bounds.X, bounds.Y, new Interval(-1, 1));

            mesh.SetTextureCoordinates(tm, Transform.Identity, true);
            var mat = new DisplayMaterial(System.Drawing.Color.White);

            mat.SetBitmapTexture(bitmap, true);
            _previewItems.Add(new HeronRasterPreviewItem()
            {
                mesh = mesh,
                mat  = mat
            });
        }
Exemplo n.º 7
0
        public static IShaderEffect Create(ShaderName name)
        {
            IShaderEffect shaderEffect;

            switch (name)
            {
                case ShaderName.Color:
                    shaderEffect = new ColorShader();
                    break;
                case ShaderName.Ambient:
                    shaderEffect = new AmbientShader();
                    break;
                case ShaderName.Diffuse:
                    shaderEffect = new DiffuseLighting();
                    break;
                case ShaderName.Specular:
                    shaderEffect = new SpecularLighting();
                    break;
                case ShaderName.Multitexture:
                    shaderEffect = new Multitexturing();
                    break;
                case ShaderName.Texture:
                    shaderEffect = new TextureMapping();
                    break;
                case ShaderName.Test:
                    shaderEffect = new TestShader();
                    break;
                case ShaderName.Bumpmaping:
                    shaderEffect = new BumpMapping();
                    break;
                case ShaderName.ParallaxMapping:
                    shaderEffect = new ParallaxMapping();
                    break;
                case ShaderName.LightingEffect:
                    shaderEffect = new LightingShader();
                    break;
                case ShaderName.DirectionalLightingParallaxMapping:
                    shaderEffect = new DirectionalLightingParallax();
                    break;
                case ShaderName.DepthShader:
                    shaderEffect = new DepthShader();
                    break;
                default:
                    shaderEffect = null;
                    break;
            }
            return shaderEffect;
        }
        private void AddSurface(Func <double, double, double> fxy)
        {
            ((UniformSurfaceChart3D)m_3dChart).SetGrid((int)N, (int)N, (float)XMin, (float)XMax, (float)YMin,
                                                       (float)YMax);

            var oldSize = 0;
            var nVertNo = (int)(N * N);

            for (var i = 0; i < nVertNo; i++)
            {
                var vert = m_3dChart[oldSize + i];

                var z = fxy(vert.x, vert.y);
                //if (!double.IsNaN(z) && !double.IsInfinity(z))
                m_3dChart[oldSize + i].z = (float)z;
            }
            m_3dChart.GetDataRange();

            // 3. set the surface chart color according to z vaule
            double zMin = m_3dChart.ZMin();
            double zMax = m_3dChart.ZMax();

            for (var i = 0; i < nVertNo; i++)
            {
                var vert  = m_3dChart[oldSize + i];
                var h     = (vert.z - zMin) / (zMax - zMin);
                var color = TextureMapping.PseudoColor(h);
                m_3dChart[oldSize + i].color = color;

                if (double.IsInfinity(vert.z) || double.IsNaN(vert.z))
                {
                    vert.z = 0;
                }
            }

            UpdateChart();
        }
Exemplo n.º 9
0
        private TextureMapping ExtractTexturemapping(JProperty property)
        {
            TextureMapping textureMapping = new TextureMapping();

            foreach (JProperty mappingProperty in property.Value.Children <JProperty>())
            {
                switch (mappingProperty.Name)
                {
                case "uscale":
                    textureMapping.UScale = mappingProperty.Value.Value <float>();
                    break;

                case "vscale":
                    textureMapping.VScale = mappingProperty.Value.Value <float>();
                    break;

                case "ushift":
                    textureMapping.UShift = mappingProperty.Value.Value <float>();
                    break;

                case "vshift":
                    textureMapping.VShift = mappingProperty.Value.Value <float>();
                    break;

                case "rotation":
                    textureMapping.Rotation = mappingProperty.Value.Value <float>();
                    break;

                case "texturelocked":
                    textureMapping.TextureLocked = mappingProperty.Value.Value <bool>();
                    break;
                }
            }

            return(textureMapping);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapModeU">Texture wrap mode for U coordinate</param>
 /// <param name="wrapModeV">Texture wrap mode for V coordinate</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, int texIndex, TextureMapping mapping, int uvIndex, float blendFactor,
     TextureOperation texOp, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, int flags) {
         FilePath = (filePath == null) ? String.Empty : filePath;
         TextureType = typeSemantic;
         TextureIndex = texIndex;
         Mapping = mapping;
         UVIndex = uvIndex;
         BlendFactor = blendFactor;
         Operation = texOp;
         WrapModeU = wrapModeU;
         WrapModeV = wrapModeV;
         Flags = flags;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Texture(Bitmap image = null, TextureMapping mapping = null, int wrapS = 0, int wrapT = 0, int magFilter = 0, int minFilter = 0, int format = 0, int type = 0, int anisotropy = 1) : this()
        {
            this.Image = image;

            this.Mapping = mapping ?? this.defaultMapping;
        }
Exemplo n.º 12
0
        private Vector4 SampleTexture(
            Vector3 worldNormal, Vector2 uv, Vector2 screenPosition,
            TextureMapping textureMapping,
            Texture2DResource diffuseTexture,
            Vector3 viewVector)
        {
            const float twoPi = 2 * 3.1415926535f;

            var t = GlobalConstantsShared.TimeInSeconds;

            switch (textureMapping.MappingType)
            {
            case TextureMappingType.Uv:
            {
                uv = new Vector2(uv.X, 1 - uv.Y);
                break;
            }

            case TextureMappingType.Environment:
            {
                uv = (Vector3.Reflect(viewVector, worldNormal).XY() / 2.0f) + new Vector2(0.5f, 0.5f);
                break;
            }

            case TextureMappingType.LinearOffset:
            {
                var offset = textureMapping.UVPerSec * t;
                uv  = new Vector2(uv.X, 1 - uv.Y) + offset;
                uv *= textureMapping.UVScale;
                break;
            }

            case TextureMappingType.Rotate:
            {
                var angle = textureMapping.Speed * t * twoPi;
                var s     = Sin(angle);
                var c     = Cos(angle);

                uv -= textureMapping.UVCenter;

                var rotatedPoint = new Vector2(
                    uv.X * c - uv.Y * s,
                    uv.X * s + uv.Y * c);

                uv = rotatedPoint + textureMapping.UVCenter;

                uv *= textureMapping.UVScale;

                break;
            }

            case TextureMappingType.SineLinearOffset:
            {
                uv.X += textureMapping.UVAmplitude.X * Sin(textureMapping.UVFrequency.X * t * twoPi - textureMapping.UVPhase.X * twoPi);
                uv.Y += textureMapping.UVAmplitude.Y * Cos(textureMapping.UVFrequency.Y * t * twoPi - textureMapping.UVPhase.Y * twoPi);
                break;
            }

            case TextureMappingType.Screen:
            {
                uv = (screenPosition / GlobalConstantsPS.ViewportSize) * textureMapping.UVScale;
                break;
            }

            case TextureMappingType.Scale:
            {
                uv *= textureMapping.UVScale;
                break;
            }

            case TextureMappingType.Grid:
            {
                uv = new Vector2(uv.X, 1 - uv.Y);
                // TODO: This should really use a uint overload of Pow.
                var numFramesPerSide = Pow(2f, textureMapping.Log2Width);
                var numFrames        = numFramesPerSide * numFramesPerSide;
                var currentFrame     = Mod(t * textureMapping.Fps, numFrames);
                var currentFrameU    = Mod(currentFrame, numFramesPerSide);
                var currentFrameV    = currentFrame / numFramesPerSide;
                uv.X += currentFrameU / numFramesPerSide;
                uv.Y += currentFrameV / numFramesPerSide;
                break;
            }
            }

            return(Sample(diffuseTexture, Sampler, uv));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="mipmaps"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        /// <param name="type"></param>
        /// <param name="mapping"></param>
        /// <param name="wrapS"></param>
        /// <param name="wrapT"></param>
        /// <param name="magFilter"></param>
        /// <param name="minFilter"></param>
        /// <param name="anisotropy"></param>
        public CompressedTexture(List <MipMap> mipmaps = null, int width = 0, int height = 0, int format = 0, int type = 0, TextureMapping mapping = null, int wrapS = 0, int wrapT = 0, int magFilter = 0, int minFilter = 0, int anisotropy = 1)
            : base(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy)
        {
            //     this.Image = { width: width, height: height }; // new Bitmap ????
            this.Mipmaps = mipmaps;

            this.GenerateMipmaps = false;
        }
Exemplo n.º 14
0
        public void Read(BinaryReader reader, int length, bool Demo = false)
        {
            ShaderType = reader.ReadUInt32();
            switch (ShaderType)
            {
            case 23:
                IntParam      = reader.ReadUInt32();
                FloatParam[0] = reader.ReadSingle();
                FloatParam[1] = reader.ReadSingle();
                break;

            case 26:
                IntParam      = reader.ReadUInt32();
                FloatParam[0] = reader.ReadSingle();
                FloatParam[1] = reader.ReadSingle();
                FloatParam[2] = reader.ReadSingle();
                FloatParam[3] = reader.ReadSingle();
                break;

            case 16:
            case 17:
                FloatParam[0] = reader.ReadSingle();
                break;

            default:
                break;
            }
            ABlending             = (AlphaBlending)reader.ReadByte();
            AlphaRegSettingsIndex = reader.ReadByte();
            ATest       = (AlphaTest)reader.ReadByte();
            ATestMethod = (AlphaTestMethod)reader.ReadByte();
            AlphaValueToBeComparedTo         = reader.ReadByte();
            ProcessMethodWhenAlphaTestFailed = (ProcessAfterAlphaTestFailed)reader.ReadByte();
            DAlphaTest     = (DestinationAlphaTest)reader.ReadByte();
            DAlphaTestMode = (DestinationAlphaTestMode)reader.ReadByte();
            DepthTest      = (DepthTestMethod)reader.ReadByte();
            UnkVal1        = reader.ReadByte();
            ShdMethod      = (ShadingMethod)reader.ReadByte();
            TxtMapping     = (TextureMapping)reader.ReadByte();
            MethodOfSpecifyingTextureCoordinates = (TextureCoordinatesSpecification)reader.ReadByte();
            Fog        = (Fogging)reader.ReadByte();
            ContextNum = (Context)reader.ReadByte();
            UnkVal2    = reader.ReadByte();
            UnkVal3    = reader.ReadByte();
            UsePresetAlphaRegSettings = reader.ReadBoolean();
            SpecOfColA      = (ColorSpecMethod)reader.ReadByte();
            SpecOfColB      = (ColorSpecMethod)reader.ReadByte();
            SpecOfAlphaC    = (AlphaSpecMethod)reader.ReadByte();
            SpecOfColD      = (ColorSpecMethod)reader.ReadByte();
            FixedAlphaValue = reader.ReadByte();
            TextureFilterWhenTextureIsExpanded = (TextureFilter)reader.ReadByte();
            AlphaCorrectionValue = reader.ReadBoolean();
            UnkFlag1             = reader.ReadBoolean();
            UnkFlag2             = reader.ReadBoolean();
            ZValueDrawingMask    = (ZValueDrawMask)reader.ReadByte();
            if (!Demo)
            {
                UnkFlag3 = reader.ReadBoolean();
                BlobFlag = reader.ReadBoolean();
                isDemo   = false;
            }
            else
            {
                UnkFlag3 = false;
                BlobFlag = false;
                isDemo   = true;
            }
            LodParamK = reader.ReadUInt16();
            LodParamL = reader.ReadUInt16();
            UnkVector1.Load(reader, 16);
            UnkVector2.Load(reader, 16);
            UnkVector3.Load(reader, 16);
            TextureId = reader.ReadUInt32();
            reader.ReadUInt32(); // Shader type
        }
Exemplo n.º 15
0
 public void SetTextureMapping(TextureMapping map)
 {
     mapping = map;
 }
Exemplo n.º 16
0
        private Vector4 SampleTexture(
            Vector3 worldNormal, Vector2 uv, Vector2 screenPosition,
            TextureMapping textureMapping,
            Texture2DResource diffuseTexture,
            Vector3 viewVector)
        {
            const float twoPi = 2 * 3.1415926535f;

            var t = GlobalConstantsShared.TimeInSeconds;

            switch (textureMapping.MappingType)
            {
            case 0:     // TEXTURE_MAPPING_UV
            {
                uv = new Vector2(uv.X, 1 - uv.Y);
                break;
            }

            case 1:     // TEXTURE_MAPPING_ENVIRONMENT
            {
                uv = (Vector3.Reflect(viewVector, worldNormal).XY() / 2.0f) + new Vector2(0.5f, 0.5f);
                break;
            }

            case 2:     // TEXTURE_MAPPING_LINEAR_OFFSET
            {
                var offset = textureMapping.UVPerSec * t;
                uv  = new Vector2(uv.X, 1 - uv.Y) + offset;
                uv *= textureMapping.UVScale;
                break;
            }

            case 3:     // TEXTURE_MAPPING_ROTATE
            {
                var angle = textureMapping.Speed * t * twoPi;
                var s     = Sin(angle);
                var c     = Cos(angle);

                uv -= textureMapping.UVCenter;

                var rotatedPoint = new Vector2(
                    uv.X * c - uv.Y * s,
                    uv.X * s + uv.Y * c);

                uv = rotatedPoint + textureMapping.UVCenter;

                uv *= textureMapping.UVScale;

                break;
            }

            case 4:     // TEXTURE_MAPPING_SINE_LINEAR_OFFSET
            {
                uv.X += textureMapping.UVAmplitude.X * Sin(textureMapping.UVFrequency.X * t * twoPi - textureMapping.UVPhase.X * twoPi);
                uv.Y += textureMapping.UVAmplitude.Y * Cos(textureMapping.UVFrequency.Y * t * twoPi - textureMapping.UVPhase.Y * twoPi);
                break;
            }

            case 5:     // TEXTURE_MAPPING_SCREEN
            {
                uv = (screenPosition / GlobalConstantsPS.ViewportSize) * textureMapping.UVScale;
                break;
            }

            case 6:     // TEXTURE_MAPPING_SCALE
            {
                uv *= textureMapping.UVScale;
                break;
            }

            case 7:     // TEXTURE_MAPPING_GRID
            {
                uv = new Vector2(uv.X, 1 - uv.Y);
                // TODO: This should really use a uint overload of Pow.
                var numFramesPerSide = Pow(2f, textureMapping.Log2Width);
                var numFrames        = numFramesPerSide * numFramesPerSide;
                var currentFrame     = Mod(t * textureMapping.FPS, numFrames);
                var currentFrameU    = Mod(currentFrame, numFramesPerSide);
                var currentFrameV    = currentFrame / numFramesPerSide;
                uv.X += currentFrameU / numFramesPerSide;
                uv.Y += currentFrameV / numFramesPerSide;
                break;
            }
            }

            return(Sample(diffuseTexture, Sampler, uv));
        }
Exemplo n.º 17
0
 private static extern ReturnCode aiGetMaterialTexture(ref AiMaterial mat, TextureType type, uint index, out AiString path, out TextureMapping mapping, out uint uvIndex, out float blendFactor, out TextureOperation textureOp, out TextureWrapMode wrapMode, out uint flags);