Ejemplo n.º 1
0
        internal ImageBuffer(SU.TextureRef suTextureRef)
        {
            SU.ImageRepRef suImageRepRef = new SU.ImageRepRef();
            SU.ImageRepCreate(suImageRepRef);

            // This gets either the non-colorized image, if the texture
            // is not colorized, or else a colorized version.

            // TODO: Find out how the HLS deltas work. Note that the
            // ability to colorize is SketchUp-specific.

            SU.TextureGetColorizedImageRep(suTextureRef, suImageRepRef);

            SU.ImageRepGetPixelDimensions(suImageRepRef, out width, out height);

            SU.ImageRepGetRowPadding(suImageRepRef, out rowPadding);

            SU.ImageRepGetDataSize(suImageRepRef, out dataSize, out bitsPerPixel);

            bytesPerPixel = bitsPerPixel / bitsPerByte;

            // Check for a match.

            if (dataSize != height * (width * bytesPerPixel + rowPadding))
            {
                throw new System.Exception("Data size of ImageRep conflicts with dimensions.");
            }

            pixelData = new byte[dataSize];

            SU.ImageRepGetData(suImageRepRef, dataSize, pixelData);
        }
Ejemplo n.º 2
0
        internal Material(SU.MaterialRef suMaterialRef)
        {
            // Get the name.

            SU.StringRef suStringRef = new SU.StringRef();
            SU.StringCreate(suStringRef);

            SU.MaterialGetNameLegacyBehavior(suMaterialRef, suStringRef);

            Name = Convert.ToStringAndRelease(suStringRef);

            // Get the types.

            SU.MaterialGetType(suMaterialRef, out suMaterialType);
            SU.MaterialGetColorizeType(suMaterialRef, out suMaterialColorizeType);

            // Get the color and/or texture.

            SU.Color      suColor;
            SU.TextureRef suTextureRef;

            switch (suMaterialType)
            {
            case SU.MaterialType_Colored:

                SU.MaterialGetColor(suMaterialRef, out suColor);

                Color = new Color(suColor);

                break;

            case SU.MaterialType_Textured:

                suTextureRef = new SU.TextureRef();

                SU.MaterialGetTexture(suMaterialRef, suTextureRef);

                Texture = new Texture(suTextureRef);

                break;

            case SU.MaterialType_ColorizedTexture:

                SU.MaterialGetColor(suMaterialRef, out suColor);

                Color = new Color(suColor);

                suTextureRef = new SU.TextureRef();

                SU.MaterialGetTexture(suMaterialRef, suTextureRef);

                Texture = new Texture(suTextureRef);

                break;

            default:
                throw new Exception($"Unknown material type = {suMaterialType}");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a texture from an image file, specifying its scale.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="xScale"></param>
        /// <param name="yScale"></param>
        public Texture(string filename, double xScale, double yScale)
        {
            SU.TextureRef textureRef = new SU.TextureRef();

            SU.TextureCreateFromFile(textureRef, filename, xScale, yScale);

            imageBuffer = new ImageBuffer(textureRef);

            SU.TextureRelease(textureRef);
        }
Ejemplo n.º 4
0
        internal void Pack()
        {
            SU.ImageRepRef suImageRepRef = new SU.ImageRepRef();

            SU.ImageRepCreate(suImageRepRef);

            SU.ImageRepSetData(
                suImageRepRef,
                imageBuffer.width,
                imageBuffer.height,
                imageBuffer.bitsPerPixel,
                imageBuffer.rowPadding,
                imageBuffer.pixelData);

            textureRef = new SU.TextureRef();

            SU.TextureCreateFromImageRep(textureRef, suImageRepRef);
        }
        public override void Run(string path)
        {
            SU.EntitiesRef entities = SUHelper.Initialize();

            SU.GeometryInputRef geometry = new SU.GeometryInputRef();
            SU.GeometryInputCreate(geometry);

            foreach (SU.Point3D p in points)
            {
                SU.Point3D pc = p;

                pc.x *= SU.MetersToInches;
                pc.y *= SU.MetersToInches;
                pc.z *= SU.MetersToInches;

                SU.GeometryInputAddVertex(geometry, pc);
            }

            SU.LoopInputRef loop = new SU.LoopInputRef();
            SU.LoopInputCreate(loop);

            SU.LoopInputAddVertexIndex(loop, 0);
            SU.LoopInputAddVertexIndex(loop, 1);
            SU.LoopInputAddVertexIndex(loop, 2);
            SU.LoopInputAddVertexIndex(loop, 3);

            long faceIndex;

            SU.GeometryInputAddFace(geometry, loop, out faceIndex);

            SU.MaterialRef material = new SU.MaterialRef();
            SU.MaterialCreate(material);
            SU.MaterialSetName(material, "Placeholder");
            SU.TextureRef texture = new SU.TextureRef();
            SU.TextureCreateFromFile(
                texture,
                "PlaceHolderRGBY.png",
                SU.MetersToInches,
                SU.MetersToInches);
            SU.MaterialSetTexture(material, texture);

            SU.MaterialInput materialInput = new SU.MaterialInput();
            materialInput.materialRef = material;
            materialInput.numUVCoords = 4;

            materialInput.materialRef = material;

            materialInput.SetUVCoords(
                new SU.Point2D(0, 0),
                new SU.Point2D(1, 0),
                new SU.Point2D(1, .5),
                new SU.Point2D(0, .5));

            materialInput.SetVertexIndices(0, 1, 2, 3);

            SU.GeometryInputFaceSetFrontMaterial(geometry, faceIndex, materialInput);


            loop = new SU.LoopInputRef();
            SU.LoopInputCreate(loop);

            SU.LoopInputAddVertexIndex(loop, 3);
            SU.LoopInputAddVertexIndex(loop, 2);
            SU.LoopInputAddVertexIndex(loop, 4);
            SU.LoopInputAddVertexIndex(loop, 5);

            SU.GeometryInputAddFace(geometry, loop, out faceIndex);

            materialInput             = new SU.MaterialInput();
            materialInput.materialRef = material;
            materialInput.numUVCoords = 4;

            materialInput.materialRef = material;

            materialInput.SetUVCoords(
                new SU.Point2D(0, .5),
                new SU.Point2D(1, .5),
                new SU.Point2D(1, 1),
                new SU.Point2D(0, 1));

            materialInput.SetVertexIndices(3, 2, 4, 5);

            SU.GeometryInputFaceSetFrontMaterial(geometry, faceIndex, materialInput);
            SU.EntitiesFill(entities, geometry, true);

            SUHelper.Finalize(path + @"\TwoQuadsSeamslessTexture.skp");
        }
Ejemplo n.º 6
0
 internal Texture(SU.TextureRef textureRef)
 {
     imageBuffer = new ImageBuffer(textureRef);
 }
        public override void Run(string path)
        {
            SU.Initialize();

            try
            {
                SU.ImageRepRef suImageRepRef = new SU.ImageRepRef();
                SU.ImageRepCreate(suImageRepRef);
                SU.ImageRepLoadFile(suImageRepRef, "PlaceHolderRGBY.png");

                long width;
                long height;

                SU.ImageRepGetPixelDimensions(suImageRepRef, out width, out height);

                Console.WriteLine("IMAGE IS {0} x {1}", width, height);

                long padding;

                SU.ImageRepGetRowPadding(suImageRepRef, out padding);

                Console.WriteLine("PADDING IS {0}", padding);

                long dataSize;
                long bitsPerPixel;

                SU.ImageRepGetDataSize(suImageRepRef, out dataSize, out bitsPerPixel);

                Console.WriteLine("DATASIZE = {0}, BPP = {1}", dataSize, bitsPerPixel);

                byte[] pixels = new byte[dataSize];

                SU.ImageRepGetData(suImageRepRef, dataSize, pixels);

                long center = 4 * ((height / 2) * (width + padding) + width / 2);

                Console.WriteLine("CENTER PIXEL = [{0}, {1}, {2}, {3}]",
                                  pixels[center],
                                  pixels[center + 1],
                                  pixels[center + 2],
                                  pixels[center + 3]);

                SU.TextureRef suTextureRef = new SU.TextureRef();

                SU.TextureCreateFromImageRep(suTextureRef, suImageRepRef);

                SU.TextureWriteToFile(suTextureRef, path + @"\TextureCopy.png");

                SU.TextureRelease(suTextureRef);

                SU.ColorOrder suColorOrder = SU.GetColorOrder();

                Console.WriteLine(
                    "RED INDEX = {0}\n" +
                    "GRN INDEX = {1}\n" +
                    "BLU INDEX = {2}\n" +
                    "ALF INDEX = {3}",
                    suColorOrder.redIndex,
                    suColorOrder.greenIndex,
                    suColorOrder.blueIndex,
                    suColorOrder.alphaIndex);

                SU.ImageRepRelease(suImageRepRef);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: {0}", e.Message);
            }
            finally
            {
                SU.Terminate();
            }
        }