Converting Unity Scenes to Vizard and SightLab VR Pro: A Comprehensive Guide

March 14, 2024

Unity and Vizard are platforms serving different realms of 3D development. Unity, with its powerful game engine, has become a staple in game development, while Vizard is a Python-based platform specializing in virtual reality applications. This article aims to guide developers through the process of converting Unity scenes to Vizard, leveraging both Unity's FBX exporter tool and the power of AI models like ChatGPT or Claude.

1. Understanding the Scene

Before diving into the conversion process, it is essential to analyze the Unity scene to understand its components, including 3D models, materials, lighting, animations, and behaviors scripted in C#.

2. Exporting Assets Using FBX Exporter
See
this article for more information on this part of the process.

2.1 Installing the FBX Exporter

In Unity, go to the Package Manager, select Unity Registry, find the FBX exporter, and install it.

2.2 Preparing the Scene for Export

  • Delete the lights in the Unity scene.
  • Select all objects in the scene through 'Edit -> Select All'.

2.3 Exporting to FBX

  • Go to 'Game Objects -> Export to FBX'.
  • Configure the options, such as choosing whether to export animations.

3. Converting to glTF (Optional)

For built-in PBR textures, you can convert the FBX file to glTF using online converters such as:

  • [miconv.com/convert-fbx-to-gltf](https://miconv.com/convert-fbx-to-gltf)
  • products.aspose.app/3d/conversion/fbx-to-gltf](https://products.aspose.app/3d/conversion/fbx-to-gltf)

4. Importing Assets into Vizard

4.1 Opening in Vizard's Inspector

Open the FBX or glTF file in Vizard's Inspector tool.

4.2 Scaling and Adjusting

- Scale the scene to the desired value, such as 0.1.

- Add lights and edit textures to achieve the needed appearance, including PBR adjustments.

5. Translating Behaviors and Scripts

5.1 Using Chat-GPT/ Claude/Gemini/CoPilot, etc. 

For complex scripts, you can leverage AI models like Chat-GPT by providing specific prompts describing the Unity code and requesting Python code for Vizard.Note for Chat-GPT, you will get far better results with the paid version using GPT-4, than the free 3.5. The new Claude 3 will work very well for coding also. 

5.2 Manual Translation

Analyze the Unity scripts and manually translate them into Python, keeping the logic and behaviors consistent.

6. Testing, Adjusting, and Optimization

- Thoroughly test the Vizard scene to ensure it behaves as expected.

- Optimize models, textures, and code for efficient performance.

7. Documentation

- Document any significant changes or deviations to maintain clear records.

8. Example Prompt

I have a Unity scene that includes a bouncing ball, which changes color every time it hits the ground. The following C# code in Unity is used to control the ball's behavior:

public class BouncingBall : MonoBehaviour
{
    private float bounceHeight = 2.0f;
    private float gravity = -9.8f;
    private float velocity = 0.0f;

    private Material material;

    void Start()
    {
        material = GetComponent<Renderer>().material;
    }

    void Update()
    {
        if (transform.position.y <= 0)
        {
            velocity = -velocity;
            ChangeColor();
        }

        velocity += gravity * Time.deltaTime;
        transform.position += new Vector3(0, velocity * Time.deltaTime, 0);
    }

    void ChangeColor()
    {
        material.color = new Color(Random.value, Random.value, Random.value);
    }
}

Could you please convert this Unity code to a Vizard script in Python that reproduces the same bouncing ball behavior, including the color change on each bounce?

Result from ChatGPT

Certainly! Below is the Python code that replicates the behavior of the bouncing ball in Vizard, as described in the provided Unity code. This script creates a ball that bounces vertically and changes color every time it hits the ground.

```python
import viz
import vizact
import random

# Set up Vizard environment
viz.go()

# Constants
bounce_height = 2.0
gravity = -9.8
velocity = 0.0

# Create a ball
ball = viz.addChild('sphere.osgb')
ball.setScale(0.2, 0.2, 0.2) # Scale to appropriate size
ball.setPosition(0, bounce_height, 0) # Set initial position

def update_ball():
    global velocity
    
    # Get current position
    x, y, z = ball.getPosition()
    
    # Check for bounce
    if y <= 0:
        velocity = -velocity
        change_color()
    
    # Update velocity and position
    velocity += gravity * viz.elapsed()
    y += velocity * viz.elapsed()
    ball.setPosition(x, y, z)

def change_color():
    r = random.random()
    g = random.random()
    b = random.random()
    ball.color(r, g, b)

# Set up an update callback to run every frame
vizact.onupdate(0, update_ball)
```

Explanation:

  • The `update_ball` function replicates the behavior described in the Unity script's `Update` method. It checks if the ball's position is at or below 0 and updates the velocity and position accordingly.
  • The `change_color` function is called every time the ball hits the ground, generating random RGB values to change the ball's color.

You might need to adjust the scale, initial position, or other parameters to fit your specific Vizard scene. Also, note that this code assumes the use of Vizard's default coordinate system and units.

Conclusion

Converting Unity scenes to Vizard can be a complex but manageable process, particularly when using tools like Unity's FBX exporter and AI models such as Chat-GPT. By following the outlined steps and paying attention to details, developers can achieve a seamless transition between these two powerful platforms, unlocking new possibilities in 3D development and virtual reality applications.

Some Common Conversions

1. Scene Management

Unity Vizard Description
SceneManager.LoadScene
vizfx.addChild
Load a new scene or add an object
SceneManager.SetActiveScene
viz.MainView.setScene
Set the active scene

2. Transformations

Unity Vizard Description
transform.position
node.setPosition
Set the position of an object
transform.rotation
node.setEuler
Set the rotation of an object
transform.localScale
node.setScale
Set the scale of an object

3. Animation

Unity Vizard Description
Animator
vizact.animate
Create and control animations

4. User Input

Unity Vizard Description
Input.GetKeyDown
viz.callback(viz.KEYDOWN_EVENT)or use vizconnect to add input device and map to an event
Key press detection
Input.GetMouseButton
viz.callback(viz.MOUSEBUTTON_EVENT)use vizconnect to add input device and map to an event
Mouse button detection

5. Physics

Unity Vizard Description
Rigidbody
viz.phys.enable() node.collideSphere()
Add physics to an object
Collider
viz.collision(viz.ON)
Enable collision detection

6. Lighting

Unity Vizard Description
Light
viz.MainView.getHeadLight().enable()
Enable or control lights

7. Materials and Textures

Unity Vizard Description
Material
viz.addMaterial
Create or apply materials
Texture
viz.addTexture
Apply textures

8. Camera Control

Unity Vizard Description
Camera.main
viz.MainView
Access the main camera

9. Hardware Setup

Unity Vizard Description
Use XR Interaction Toolkit or set up using third party packages
Use the Vizconnect GUI or add in code
Set up hardware
Stay Updated
Subscribe to our monthly Newsletter
CONTACT US 
Phone +1 (888) 841-3416
Fax +1 (866) 226-7529
813 Reddick St
Santa Barbara, CA 93103