Wednesday, September 4, 2024

Quick Solver: UIElement Screen position from world position

Get screen position of UI Toolkit element

Valid for:

Unity 2023.2.20f1 (tested), 2022.3
com.unity.ui@2.0.0 - UI Toolkit

Use RuntimePanelUtils.CameraTransformWorldToPanel to convert the element's world position to panel coordinates, then set the element's translate style property.


var panelLocalPosition = RuntimePanelUtils.CameraTransformWorldToPanel(
    element.panel, worldPosition, Camera.main);
element.style.translate = new StyleTranslate(
    new Translate(panelLocalPosition.x, panelLocalPosition.y, 0));


Additional Information

Moving the element turned out to be tricky, but StyleTranslate worked best in the end. 

Links to Discussions


Conclusion

Getting the screen position of a UI Toolkit element requires converting between the world space position and the panel's local coordinate system. The RuntimePanelUtils class provides methods to handle this conversion.

The code above allows you to move an UI Element on top of a gameobject (e.g. for RTS like games, name tags, health bars or HUD Elements).

Common issues that arise are accidentally using RectTransforms instead of VisualElements, or assuming the position is in screen space coordinates.

When working with UI Toolkit, always consider what coordinate space you are in and use the appropriate conversion methods as needed to translate between world, panel, and screen spaces.

Tuesday, August 13, 2013

Quicksolver: Export Blender Video as mp3

Blender is not only a 3d Modelling Software, but also a great OpenSource Video Editing Software. It's also decent for quick Audio Editing. I used it for an Audio Drama project, since I didn't want to use expensive Software.
Since it isn't very obvious on how to export your project to mp3, here is a little tutorial:

1. Go into the Render menu in the Properties tab

2. Select MPEG as fileformat
3. In the Encoding options, select Mp3 as Format
4. Additionally you can change the Bitrate

P.S.: I spent hours of searching and trying before I found this option. You could also use this to extract Audio from Videos and arrange them together (severall Youtube Video Parts to one mp3).

Sunday, May 26, 2013

From gaming to marketing: The XBOX ONE and the future of Entertainment

The XBOX One should be the next big hit, not only in gaming, but also in entertainment. Many great features and a modern Hardware that can compete with average Computers. All in One Box. It even comes with the Kinect, the new interface between Human and XBOX. It seems Microsoft really wanted to give the consumers everything they wanted.
But behind all that technology is always Software that watches you.

Thursday, May 23, 2013

Quicksolver: My Unity Lightmaps look bad

Problem

My lightmaps in Unity look really bad and ugly.

Solution

  • Untick "Compressed". This decompresses your lightmaps and makes their file size bigger. Uncompressed Lightmaps look a lot smoother.
  • Set your bake quality to "High" and change the resolution.

Result


Quicksolver: Unity Beast Lightmapper Problem

Problem

When I upgraded from Unity 3.5 to version 4 I had problems with Unity's Lightmapping tool Beast. It has worked fine in 3.5 but completely refused working in Unity 4. I kept getting the Error "Nothing to bake. None of the Mesh Renderers or Terrains in the scene are marked as static. Only static objects will be lightmapped".

Solution

Make sure you ticked "Generate Lightmap UVs" in the Import Settings. It seems to be necessary in the new Version, although it worked fine in the old.



Still not working?


  • Check if your Objects are static in lightmapping

  • Is "Use Lightmapping" on?

  • Check if you have meshes and lights in your current scene

Saturday, April 13, 2013

Video Experiments

Some video experiments I did for fun in my spare time.

Fun with physic

Sketchup with sketchy physic



After I advanced a little I tried out more in Blender


Fractals

Those are very hard to explain, but look very cool, so I rendered them in 3D.



Video effects

A slow-motion test.


After waiting hours for snow to melt, I decided my time-lapse would look even "cooler" if I reversed it.


A very wild frame blending effect I programmed and rendered in processing.


Just for fun

Why not attach your mobile phone to an rc-boat and film?


Saturday, March 9, 2013

Arduino and ATtiny

Shrinkify arduino


An arduino is a nice piece of hardware and considerable cheap. But sometimes you need your projects to be smaller or cheaper. The shrinkify arduino project from m.I.t (link) is exactly the right thing for a blinking light example. An inexpensive ATtiny 45 (5 usable pins) or 84 (11 usable pins) is enough. They cost about 2 euro.
You don't even need to buy a programmer. A full size arduino can be used.


Arduino as In-System-Programmer (ISP)

There is a very good guide on how to set up your arduino as an ISP here.


Servos

Since the AtTiny doesn't have a 16 bit timer, which is necessary to generate a servo impulse, you need to use the software servo library.
Make sure you to call refresh() at the end of each update, or it won't work.


Problems that can occur

  • Wrong side. Make sure your chip is correctly aligned.
  • Defect cable or no contact. Make sure you test your connections. Don't forget to check your USB connection. The arduino is very picky about USB-cables and doesn't work with some cables, or suddenly refuses to use a previously working cable.
  • Baudrate not to 9600 in ISP and arduino Ide. Some chips require a lower baudrate. Make sure to change it to 9600 in the ISP code, and also in the programmers.txt located in \arduino-1.0.3\hardware\arduino
from
arduinoisp.speed=19200
to
arduinoisp.speed=9600
  • My code is running faster or slower. Most chips have a different clockspeed than the arduino, but you can change this easily by installing the right bootloader on your chip. You can do this in the arduino ide under Tools/Install bootloader. Make sure you have the right board and the right clock speed selected.


Extended Version: Programmer board for arduino (Uno)

If you want to programm your chips more than once, you should consider making a board for your arduino.


Luxury version

Just buy a TinyProgrammer :)



Friday, February 8, 2013

Walimex lens for mobile phone

Walimex lens for mobile phones


The Walimex lenses are actually made for IPhones, but fit nicely on nearly any phone or tablet (even the Blackberry Playbook). The lens gets attached via a magnetic ring that sticks to the phone, so you don't have to walk around with it all the time.

Since Walimex is a well known DSLR-lens manufacturer, I thought I give it a try. I got a fisheye and a telephoto lens.


The lenses came with covers for front and back, which is great for carrying around in a bag, without damaging them.

Testphotos:

All photos are made with my Nexus 4.

Without lens


With fisheye 180°





With telephoto lens 2x




More fisheye fotos


Conclusion

The photos are great and creative. Initially I bought them for panoramic pictures (since photosphere and the panorama function are quite messy), but they are great, especially if you want to see more on your pictures.

They are cheaper if you buy them in a set, and I am thinking of getting more of them.


Have fun, DrFritzi