Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How the create The .png texture? #1

Closed
Ants-double opened this issue Mar 13, 2018 · 4 comments
Closed

How the create The .png texture? #1

Ants-double opened this issue Mar 13, 2018 · 4 comments

Comments

@Ants-double
Copy link

I see the volumer endering use a .png to mipmaping the cubeTex: "./.png", ,Now I have the Volume data .But i can't generat the png image. Help.tell me how to change the RAW data to png texture.Thank you.

@MikesWei
Copy link
Owner

@MikesWei
Copy link
Owner

JavaScript code:

      function convert3DTexture(rawData, width, height, depth, flipY) {
        var newWidth = width * maxTilesWidth;
        var newHeight = height * maxTilesHeight;
        var canvas = document.createElement('canvas');
        canvas.height = newHeight;
        canvas.width = newWidth;
        var ctx = canvas.getContext('2d');
        var imageData = ctx.getImageData(0, 0, newWidth, newHeight);

        var realPosX, realPosY;
        var index = 0;

        for (var z = 0; z < depth; z++) {
            for (var y = 0; y < height; y++) {
                for (var x = 0; x < width; x++) {
                    var value = rawData[index++];

                    realPosX = x + (z % maxTilesHeight) * width;

                    var yPos;
                    if (flipY) {
                        yPos = height - y - 1;
                    }
                    else {
                        yPos = y;
                    }

                    realPosY = yPos + parseInt(z / maxTilesWidth) * height;
                    var colorIdx = realPosX + realPosY * newWidth;
                    colorIdx *= 4;
                    imageData.data[colorIdx] = value;
                    imageData.data[colorIdx + 1] = value;
                    imageData.data[colorIdx + 2] = value;
                    imageData.data[colorIdx + 3] = value;

                }
            }
        }
        ctx.putImageData(imageData, 0, 0);
        return canvas;
    }

@Ants-double
Copy link
Author

Ants-double commented Mar 14, 2018

Thank you ,Now i get the canvas ,then ,i met the error ,when i put the canvas to the cubeTex:,the show nothing. Thank for you help,i use canvas.toDataURL('image/png');but not show the volume rendering.

@Ants-double
Copy link
Author

ye. i use the C# code generate the texture ,it's work Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants