Rotate Image

474 views
Skip to the first unread message

Tamy

unread,
5 Dec 2012, 7:04:10 am5/12/12
to cesiu...@googlegroups.com
Can I rotate an Image?

       var image = new Image();
        image.onload = function() {
            var billboard = new Cesium.BillboardCollection();
            var textureAtlas = scene.getContext().createTextureAtlas({
                image : image
            });
            billboard.setTextureAtlas(textureAtlas);
            img = billboard.add({
                position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(x, y, z)),
                imageIndex : 0
            });
            primitives.add(billboard);
        };
        image.src = '../../Images/image.png';


before:  after:

Thank you!



Patrick Cozzi

unread,
9 Dec 2012, 9:05:36 am9/12/12
to cesiu...@googlegroups.com
Hi Tamy,

Billboards do not support rotating an image yet, but I believe you can do it with CSS.

Patrick


Tamy

unread,
10 Dec 2012, 6:46:14 am10/12/12
to cesiu...@googlegroups.com
Thank you Patrick,

I can rotate an image with css through javascript in a html page (Google Chrome):

<script type="text/javascript">
    var image = new Image();
    image.src = 'image.png';
    image.style.webkitTransform = "rotate(90deg)";
    document.body.appendChild(image);
</script>

but it doesn't work in Cesium:

var image = new Image();
image.src = 'image.png';
image.style.webkitTransform = "rotate(90deg)"; //putting it here or...
image.onload = function() {
            image.style.webkitTransform = "rotate(90deg)"; //putting it here
            var billboards = new Cesium.BillboardCollection();
            var textureAtlas = scene.getContext().createTextureAtlas({image : image});
            billboards.setTextureAtlas(textureAtlas);
            billboards.add({
                position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
                imageIndex : 0
            });
            scene.getPrimitives().add(billboards);
};


 image.style.webkitTransform - Google Chrome
 image.style.MozTransform - Firefox

Do you have any idea why is it  happening?

Matthew Amato

unread,
10 Dec 2012, 9:59:35 am10/12/12
to cesiu...@googlegroups.com
I'm fairly certain that WebGL only supports creating textures from the original source image "as is".  Any transforms applied by the browser, via CSS or other means (such as modifying the width/height properties in Javascript) do not translate into the resulting texture.  I'm not 100% positive on this, but I ran into a similar problem when trying to dynamically resize images.  I wonder what WebGL spec says on the subject.

The workaround in this case would be:

1. Create a new Canvas
2. Draw the rotated image onto the canvas
3. Make a texture out of the canvas

The above should definitely work, but in the long run we definitely should support rotation at the primitive level.

--
 
 

Ed Mackey

unread,
10 Dec 2012, 10:19:52 am10/12/12
to cesiu...@googlegroups.com
Guys, shouldn't the billboard primitive have its own screen-space rotation angle that can be changed at runtime without rebuilding the texture?

       --Ed.



--
 
 

Patrick Cozzi

unread,
10 Dec 2012, 10:23:02 am10/12/12
to cesiu...@googlegroups.com
I think Matt is right.  Ed, we will add that feature as priorities allow.  Given that it is non-trivial to stay under the guaranteed maximum number of WebGL vertex attributes, I do not see us doing it in the short-term.

Patrick


Scott Hunter

unread,
10 Dec 2012, 10:33:00 am10/12/12
to cesiu...@googlegroups.com
One other thing to keep in mind when trying the canvas approach is that the canvas will need to be bigger than the original image, in order to fit the rotated image, since both must be rectangular.  As a result, the image created from the canvas will have transparent corners, and because billboards are drawn in a fixed order regardless of where the camera is, you can end up with artifacts when the alpha-blending is done in the wrong order from the camera's perspective.

Ed Mackey

unread,
10 Dec 2012, 10:44:08 am10/12/12
to cesiu...@googlegroups.com
Cozzi, understood.  Here's a goofy idea: Could the rotation angle sneak in as the last value of a vec4 position attribute?

   --Ed.


On Mon, Dec 10, 2012 at 10:33 AM, Scott Hunter <para...@gmail.com> wrote:
One other thing to keep in mind when trying the canvas approach is that the canvas will need to be bigger than the original image, in order to fit the rotated image, since both must be rectangular.  As a result, the image created from the canvas will have transparent corners, and because billboards are drawn in a fixed order regardless of where the camera is, you can end up with artifacts when the alpha-blending is done in the wrong order from the camera's perspective.

--
 
 

Matthew Amato

unread,
10 Dec 2012, 10:45:13 am10/12/12
to cesiu...@googlegroups.com
Ed,

As Cozzi stated, you are absolutely correct, the primitive should support it.  In addition to finding the time to do it, we also have to keep in mind that rotation can get a little tricky when you allow the map to be oriented any way other than "north" being up in screen space.  We need to be able to specify the rotation in such a way so that pointing is view dependent.  This is why it just can't be a simple "rotation" property but also has to have some sort of reference direction associated with it.  Insight3D has these capabilities (Bagnell added them) so it's something we have experience with, we just need to do it.  It's unclear whether this extra information needs to be passed to the shader or if the shader only needs the final rotation.

--
 
 

Patrick Cozzi

unread,
10 Dec 2012, 11:43:23 am10/12/12
to cesiu...@googlegroups.com
Ed - we already pack attributes like mad.  We need to explore compressing them.  I have plenty of ideas.  When it's high enough priority, we'll investigate.

--
 
 



--
www.seas.upenn.edu/~pcozzi/

Daniel Bagnell

unread,
17 June 2013, 2:33:53 pm17/6/13
to cesiu...@googlegroups.com
Hi Tamy,

Billboard rotation is now available in master and will be in the next release. You might want to update your code because it will be faster than drawing the rotated image to a canvas.

Regards,
Dan

Tamy

unread,
17 June 2013, 2:57:37 pm17/6/13
to cesiu...@googlegroups.com
Very nice! Thanks!

nagab...@gmail.com

unread,
8 Sept 2015, 11:11:37 am8/9/15
to cesium-dev
> before:  after:
> Thank you!

Hi,

I know your post is a couple of years old. I am new to this - how did you get the billboard to rotate for you ?

thanks
Nagi

Hannah Pinkos

unread,
8 Sept 2015, 1:37:59 pm8/9/15
to cesium-dev, nagab...@gmail.com
Hello Nagi,

Billboard has a rotation property.  Here's a code example:

    viewer.entities.add({
        position
: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
        billboard
:{
            image
: '../images/Cesium_Logo_overlay.png',
            rotation
: Cesium.Math.toRadians(90)
       
}
   
});


Best,

Hannah
Reply all
Reply to author
Forward
0 new messages