Forum Discussion
Infinite
12 years agoHonored Guest
Human scans in Unity. Unity dev help needed.
Hi all,
I'm trying to find the right place to ask if anyone can help me with Unity. I'm trying to publish some nude human scan assets so people can view them with Unity on the Rift. Similar to these:
https://vimeo.com/64769947
I have very little Unity experience. So far I can get my assets in no problem with the Rift OVRPlayerController and build a .exe but I'm trying to find out how to add a free roaming flying camera (script?), that works with the Rift rendering and OVRPlayerController.
I'm trying to match the smoothness of the controls in UDK. Whereby you can activate 'fly' and 'slowmo 0.3' to control camera flight and speed. I would publish with UDK but it doesn't seem as universal or as user friendly as a Unity pack.
Any help would be greatly appreciated and perhaps rewarded with some cool nude scan demos!
I'm trying to find the right place to ask if anyone can help me with Unity. I'm trying to publish some nude human scan assets so people can view them with Unity on the Rift. Similar to these:
https://vimeo.com/64769947
I have very little Unity experience. So far I can get my assets in no problem with the Rift OVRPlayerController and build a .exe but I'm trying to find out how to add a free roaming flying camera (script?), that works with the Rift rendering and OVRPlayerController.
I'm trying to match the smoothness of the controls in UDK. Whereby you can activate 'fly' and 'slowmo 0.3' to control camera flight and speed. I would publish with UDK but it doesn't seem as universal or as user friendly as a Unity pack.
Any help would be greatly appreciated and perhaps rewarded with some cool nude scan demos!
42 Replies
Replies have been turned off for this discussion
- drashHeroic ExplorerI'll post what I've got for smooth Rift-compatible flight (uses Unity's out-of-the-box Horizontal/Vertical/Mouse X inputs). But, my script doesn't play well with OVRPlayerController at all (OVRCameraController only), so it may or may not meet your needs. I'm just going to dump some step-by-step instructions for using it to be as clear as possible, so don't take it personally if I "explain it like you're 5". :)
Step 1: Create the following scene hierarchy structure for an OVRCameraController, where CameraBase is basically an empty GameObject for now (you don't have to call it CameraBase). If you have an OVRPlayerController, delete your OVRPlayerController and everything under it and replace it with the following. (I'm going to assume that if you've made any modifications to the out-of-the-box OVRPlayerController and its child OVRCameraController object that you will remember what changes you made for future reference etc.)
(Also, the advantage of having a "CameraBase" object like this is that you can also attach a normal camera as a child (next to OVRCameraController), and then by making either this non-Rift camera or the OVRCameraController active, you can set up a non-stereoscopic vs Rift-mode toggle or something.)
Step 2: Copy and save the following script into a C# script called FlightCamera.cs and move it into your Project's Assets.using UnityEngine;
public class FlightCamera : MonoBehaviour
{
public bool requireMouseButtonForLooking = false;
public bool useLeftMouseButtonForLooking = true;
public bool useLookSmoothing = true;
public float mouselookSmoothingFactor = 0.2f;
public float mouselookSpeed = 2000f;
public bool mouselookOnlyAffectsYaw = false;
public Transform useForwardDirectionFromOtherObject;
public float movementSpeed = 1f;
public float movementSmoothingFactor = 0.2f;
public KeyCode upKey = KeyCode.E;
public KeyCode downKey = KeyCode.Space;
public float sprintMultiplier = 1.5f;
public KeyCode sprintKey = KeyCode.LeftShift;
private float rotationX = 0f;
private float rotationY = 0f;
private Quaternion initialRotation;
private Quaternion targetRotation;
private Vector3 targetPosition;
private Vector3 currentVelocity;
void Start ()
{
initialRotation = transform.rotation;
targetRotation = initialRotation;
targetPosition = transform.position;
currentVelocity = Vector3.zero;
}
void LateUpdate ()
{
#region Mouselook
KeyCode mouseButton = KeyCode.Mouse0;
if(!useLeftMouseButtonForLooking)
mouseButton = KeyCode.Mouse1;
if(requireMouseButtonForLooking == false ||
requireMouseButtonForLooking == true && Input.GetKey(mouseButton))
{
float mouseInputMultiplier = mouselookSpeed / (float)Mathf.Min(Screen.height, Screen.width);
rotationX += Input.GetAxis("Mouse X") * mouseInputMultiplier;
if(!mouselookOnlyAffectsYaw)
rotationY += Input.GetAxis("Mouse Y") * mouseInputMultiplier;
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
targetRotation = initialRotation * xQuaternion * yQuaternion;
Quaternion currentRotation = transform.rotation;
if(!Approximately(currentRotation, targetRotation))
transform.rotation = Quaternion.Slerp(currentRotation, targetRotation, mouselookSmoothingFactor);
}
#endregion
#region Movement
float movementMultiplier = movementSpeed * Time.deltaTime * (Input.GetKey(sprintKey) ? sprintMultiplier : 1f);
Quaternion rotationToFaceForward = targetRotation;
if(useForwardDirectionFromOtherObject != null)
rotationToFaceForward = useForwardDirectionFromOtherObject.rotation;
float forwardBackwardTranslation = Input.GetAxisRaw("Vertical") * movementMultiplier;
float leftRightTranslation = Input.GetAxisRaw("Horizontal") * movementMultiplier;
float upMultiplier = Input.GetKey(upKey) ? 1f : 0f;
float downMultiplier = Input.GetKey(downKey) ? -1f : 0f;
float upDownTranslation = (upMultiplier + downMultiplier) * movementMultiplier;
Vector3 movementVector = new Vector3(leftRightTranslation, upDownTranslation, forwardBackwardTranslation);
if(movementVector != Vector3.zero)
{
movementVector = rotationToFaceForward * movementVector;
targetPosition += movementVector;
}
Vector3 currentPosition = transform.position;
if(!Approximately(currentPosition, targetPosition))
{
currentPosition = Vector3.SmoothDamp(currentPosition, targetPosition, ref currentVelocity, movementSmoothingFactor, float.PositiveInfinity, Time.deltaTime);
transform.position = currentPosition;
}
#endregion
}
private bool Approximately(Quaternion q1, Quaternion q2)
{
return Mathf.Approximately(q1.x, q2.x) &&
Mathf.Approximately(q1.y, q2.y) &&
Mathf.Approximately(q1.z, q2.z) &&
Mathf.Approximately(q1.w, q2.w);
}
private bool Approximately(Vector3 v1, Vector3 v2)
{
return Mathf.Approximately(v1.x, v2.x) &&
Mathf.Approximately(v1.y, v2.y) &&
Mathf.Approximately(v1.z, v2.z);
}
}
Step 3: Drag the FlightCamera script onto the CameraBase object, and make FlightCamera component's properties look exactly like this: (Note that you'll have to drag the OVRCameraController's CameraRight gameobject from the hierarchy into the "Use Forward Direction From Other Object" property field.)
Step 4: On your OVRCameraController, you'll want to drag the CameraBase gameobject from the hierarchy into the "Follow Orientation" property field, so that it looks like this:
Step 5: Since you're no longer using the OVRPlayerController prefab, if you want to still have the functionality of being able to hit Space to bring up the Rift menu (to see a framerate readout, and for adjusting Rift-specific stuff like mag calibration, IPD, FOV, etc), you can simply drag the OVRMainMenu script onto the OVRCameraController gameobject. I noticed that you also want to be able to use Spacebar to move the flight camera down, so I would suggest resolving this conflict by either changing the "Down Key" on the FlightCamera component on CameraBase, or by changing the OVRMainMenu script code by finding the GUIShowVRVariables() function, and changing the line that saysbool SpaceHit = Input.GetKey("space");tobool SpaceHit = Input.GetKey(KeyCode.???);
where ??? is the key of your choice.
Very impressed with your work so far, so I hope that helps! - InfiniteHonored Guest
"drash" wrote:
I'll post what I've got for smooth Rift-compatible flight (uses Unity's out-of-the-box Horizontal/Vertical/Mouse X inputs). But, my script doesn't play well with OVRPlayerController at all (OVRCameraController only), so it may or may not meet your needs. I'm just going to dump some step-by-step instructions for using it to be as clear as possible, so don't take it personally if I "explain it like you're 5". :)
Very impressed with your work so far, so I hope that helps!
Damn! thank you. Really comprehensive guide. Worked first time. That must have taken you ages to write out. My inner 5 year old was very happy :D
I really need to learn more about scripting to understand what I am doing, I have to work on that.
I will make sure I share some cool scans for you to check out if your interested. Just PM me at some point.
This is really cool!! Very fluid.
EDIT**
I've just had a play with the settings and I seem to be getting the right kind of movement. Massive thanks for your help on this. REALLY useful. I hope to share some data soon. :)
With the new effects possible in Unity, combined with the massive open architecture for scripting etc combined with the Rift and VR this really opens up some crazy wild possibilities. Very exciting. - SDMExplorerGlad you got the script you wanted. Was hoping a seasoned pro would chime in and lead you down a better path for this than I could at this point, very glad that drash did. I'm very rusty on the code side any more, 3d modeling has been my focus for a long time (and your scans/models are literally awe inspiring), but trying to relearn all I have forgotten -and of course more. The Rift and the potential it holds for so many things is truly amazing, great incentive to get back into this.
Any way, glad my post above could tide you over till the good stuff came along. Good luck with your Unity project/s, I'm sure they'll be amazing. - InfiniteHonored Guest
"SDM" wrote:
Glad you got the script you wanted. Was hoping a seasoned pro would chime in and lead you down a better path for this than I could at this point, very glad that drash did. I'm very rusty on the code side any more, 3d modeling has been my focus for a long time (and your scans/models are literally awe inspiring), but trying to relearn all I have forgotten -and of course more. The Rift and the potential it holds for so many things is truly amazing, great incentive to get back into this.
Any way, glad my post above could tide you over till the good stuff came along. Good luck with your Unity project/s, I'm sure they'll be amazing.
Thanks SDM. Your initial guidance for movement control got me hooked into Unity, a great start :) and nice welcome to the forum, I appreciate that.
I hope anyone else who stumbles on this thread can take a way this useful information that others kindly shared. - BoffExplorerJust posting here so I can find these lovely code snippets at a later date....
Thanks all! - CaliberMengskExplorerI'm a bit late to the show, but if the OVR controller is based on the physics engine of unity (and if it's programmed correctly, it will), you should simply be able to set gravity to zero.
You can either add code:
Physics.gravity = Vector3.zero;
Or if you always want it off, just click edit > Project Settings > Physics. Then you just set gravity there.
:D It's quite fun to mess with gravity too. I made a game last game jam where the gravity changed based on the orientation of the phone. Boxes flying everywhere. XD - SlopeyHonored Guest@Infinite
Love the 3D-Scan-Girl demo - fantastic quality capture, and with some rigging in there, the potential for developers in Unity is amazing with such fidelity!
Can I ask how you did the animated "traffic" surrounding the scene (the far off lights/city scape)? I'm guessing it's attached to the camera as a sort of skybox, but it's a fantastic effect I'd like to emulate in one of my projects.
(also in the 3D-Scan-Girl readme, "R" is listed for up, but it appears to be "E" ;) ) - drashHeroic ExplorerYes, nice work on that 3D-Scan-Girl01 demo -- I'm pretty blown away by the detail (I seriously feel like the eyes could move to look at me at any time), and as Slopey above, the atmosphere with the far-off city lights and traffic is pretty dang cool. Bravo!
- InfiniteHonored Guest
"CaliberMengsk" wrote:
I'm a bit late to the show, but if the OVR controller is based on the physics engine of unity (and if it's programmed correctly, it will), you should simply be able to set gravity to zero.
You can either add code:
Physics.gravity = Vector3.zero;
Or if you always want it off, just click edit > Project Settings > Physics. Then you just set gravity there.
:D It's quite fun to mess with gravity too. I made a game last game jam where the gravity changed based on the orientation of the phone. Boxes flying everywhere. XD
Ahh thanks! that could have been handy. :D"Slopey" wrote:
@Infinite
Love the 3D-Scan-Girl demo - fantastic quality capture, and with some rigging in there, the potential for developers in Unity is amazing with such fidelity!
Can I ask how you did the animated "traffic" surrounding the scene (the far off lights/city scape)? I'm guessing it's attached to the camera as a sort of skybox, but it's a fantastic effect I'd like to emulate in one of my projects.
(also in the 3D-Scan-Girl readme, "R" is listed for up, but it appears to be "E" ;) )
Many thanks. Glad you enjoyed it, I appreciate the cool feedback. I'm going to try an animated mocap example soon. I also want to post another question regarding streaming .obj files. Or a way to swap in and out meshes quickly at 24 fps. But I guess these forums aren't the best place to ask. With this technique I could show a basic 4D demo (animated scans through time)
The traffic was old school. I love these hacks, I used to use them during my PS and PS2 dev days making game levels. They are just 2 cylinders rotating passed each other, slowly, with little dots on them, behind that - city light cylinder, in front of all, a heat ripple effect (which also slowly rotates) which you can get on the Unity store! I'm having sorting issues on that though, as you can see it also effects the girls skin. It all works on the Rift because of the low res.
Maybe I can share some assets at some point.
Damn I need to adjust the "E" thing!!"drash" wrote:
Yes, nice work on that 3D-Scan-Girl01 demo -- I'm pretty blown away by the detail (I seriously feel like the eyes could move to look at me at any time), and as Slopey above, the atmosphere with the far-off city lights and traffic is pretty dang cool. Bravo!
Thanks drash!! Appreciate that. Sadly, no one noticed her heart beat yet :) well the sound of it! Unity rocks.
For anyone interested in the movement side of things with regards to scanning, I posted a question here http://forum.unity3d.com/threads/193959-Sequenced-obj-mesh-streaming?p=1316901#post1316901 over at the Unity forums, as it's not really Rift related. I would be interested to know what you guys think about a solution for mesh streaming? - CaliberMengskExplorerUnity is indeed awesome.
T_T Unfortunately, me as a hobbiest, it's really hard to find time. T_T
You can develop stuff extremely fast in Unity though. At the last game jam, we had a nearly polished game in the 48 hour span. Looked pretty too. http://www.stlgamejam.com/game-recap-turned-out/ if you want to see what 48 hours can be.
It would be pretty awesome to see one of these scans being able to do full motion. With the proper shaders, it could turn into an amazing show piece.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 10 days ago
- 9 months ago
- 1 month ago