Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Charuzu · Apr 13, 2016 at 07:48 PM · kinectstartup

Nothing is being added to frame or being displayed

I am writing a program that pulls Kinect joints from a saved file and then loops through each frame, draws the joints, and stops once the end of file has been reached. I am using the official Kinect plugin from Microsoft. However, when I run the program, no errors are being displayed but nothing is added to the render environment. I am very new to Unity, so I have no idea what could be going on.

The data types CustomBody and CustomFrame are custom objects that I made. The CustomFrame has a list of CustomBodies, and each CustomBody has a dictionary of Kinect joints which is what's needed to actually position the bodies once rendered.

Here is my code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using Kinect = Windows.Kinect;
 using System;
 using System.IO;
 using UnityEditor;
 
 [InitializeOnLoad]
 public class RenderFromFile : MonoBehaviour
 {
     private GameObject gObject;
 
     static RenderFromFile()
     {
         Debug.Log("Render file has been started");
     }
 
     void Start()
     {
         if (_frameCollection.Count == 0)
         {
             readFromFile();
         }
         else
         {
             Update();
         }
 
     }
 
     void Update()
     {
         if (frameCount < _frameCollection.Count - 1)
         {
             showAnimation(frameCount);
             frameCount++;
         }
         else
         {
             var textArea = new Rect(0, 0, Screen.width, Screen.height);
             GUI.Label(textArea, "End of file has been reached");
         }
     }
 
     private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
     {
         { Kinect.JointType.FootLeft, Kinect.JointType.AnkleLeft },
         { Kinect.JointType.AnkleLeft, Kinect.JointType.KneeLeft },
         { Kinect.JointType.KneeLeft, Kinect.JointType.HipLeft },
         { Kinect.JointType.HipLeft, Kinect.JointType.SpineBase },
 
         { Kinect.JointType.FootRight, Kinect.JointType.AnkleRight },
         { Kinect.JointType.AnkleRight, Kinect.JointType.KneeRight },
         { Kinect.JointType.KneeRight, Kinect.JointType.HipRight },
         { Kinect.JointType.HipRight, Kinect.JointType.SpineBase },
 
         { Kinect.JointType.HandTipLeft, Kinect.JointType.HandLeft },
         { Kinect.JointType.ThumbLeft, Kinect.JointType.HandLeft },
         { Kinect.JointType.HandLeft, Kinect.JointType.WristLeft },
         { Kinect.JointType.WristLeft, Kinect.JointType.ElbowLeft },
         { Kinect.JointType.ElbowLeft, Kinect.JointType.ShoulderLeft },
         { Kinect.JointType.ShoulderLeft, Kinect.JointType.SpineShoulder },
 
         { Kinect.JointType.HandTipRight, Kinect.JointType.HandRight },
         { Kinect.JointType.ThumbRight, Kinect.JointType.HandRight },
         { Kinect.JointType.HandRight, Kinect.JointType.WristRight },
         { Kinect.JointType.WristRight, Kinect.JointType.ElbowRight },
         { Kinect.JointType.ElbowRight, Kinect.JointType.ShoulderRight },
         { Kinect.JointType.ShoulderRight, Kinect.JointType.SpineShoulder },
 
         { Kinect.JointType.SpineBase, Kinect.JointType.SpineMid },
         { Kinect.JointType.SpineMid, Kinect.JointType.SpineShoulder },
         { Kinect.JointType.SpineShoulder, Kinect.JointType.Neck },
         { Kinect.JointType.Neck, Kinect.JointType.Head },
     };
     public Material BoneMaterial;
     public GameObject BodySourceManager;
     private List<GameObject> _allBodies = new List<GameObject>();
     private List<CustomFrame> _frameCollection = new List<CustomFrame>();
     private string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
     private int frameCount = 0;
 
     private void readFromFile()
     {
         String fileName = System.IO.Path.Combine(path, "KinectTest.bin");
 
         using (Stream stream = File.Open(fileName, FileMode.Open))
         {
             var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
             _frameCollection = (List<CustomFrame>)bformatter.Deserialize(stream);
         }
 
         /*
         //For testing purposes
         fileName = System.IO.Path.Combine(path, "KinectDuplicateTest.bin");
         using (Stream stream = File.Open(fileName, FileMode.Create))
         {
             var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
             bformatter.Serialize(stream, frameCollection);
         }
         */
         var textArea = new Rect(0, 0, Screen.width, Screen.height);
         GUI.Label(textArea, "File has been read in");
 
         Update();
     }
 
     void showAnimation(int frameNum)
     {
         //need to delete existing beforehand
         _allBodies.Clear();
 
         CustomFrame frame = _frameCollection[frameNum];
         List<CustomBody> _bodies = new List<CustomBody>();
         _bodies = frame.getBodies();
 
         for (int i = 0; i < _bodies.Count; i++) //create and set each body
         {
             _allBodies.Add(CreateBodyObject(i));
             RefreshBodyObject(_bodies[i], _allBodies[i]);
         }
     }
 
     private GameObject CreateBodyObject(int location)
     {
         GameObject body = new GameObject("Body:" + location);
 
         for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
         {
             GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
 
             LineRenderer lr = jointObj.AddComponent<LineRenderer>();
             lr.SetVertexCount(2);
             lr.material = BoneMaterial;
             lr.SetWidth(0.05f, 0.05f);
 
             jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
             jointObj.name = jt.ToString();
             jointObj.transform.parent = body.transform;
         }
 
         return body;
     }
 
     private void RefreshBodyObject(CustomBody body, GameObject bodyObject)
     {
         for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
         {
             Kinect.Joint sourceJoint = body.joint[jt];
             Kinect.Joint? targetJoint = null;
 
             if (_BoneMap.ContainsKey(jt))
             {
                 targetJoint = body.joint[_BoneMap[jt]];
             }
 
             Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
             jointObj.localPosition = GetVector3FromJoint(sourceJoint);
 
             LineRenderer lr = jointObj.GetComponent<LineRenderer>();
             if (targetJoint.HasValue)
             {
                 lr.SetPosition(0, jointObj.localPosition);
                 lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                 lr.SetColors(Color.green, Color.red);
             }
             else
             {
                 lr.enabled = false;
             }
         }
     }
 
     private static Vector3 GetVector3FromJoint(Kinect.Joint joint)
     {
         return new Vector3(joint.Position.X * 10, joint.Position.Y * 10, joint.Position.Z * 10);
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity doesn't show login screen after startup 1 Answer

Unity windows crashes on startup 2 Answers

Unity 3d exe with graphics auto start of the machine / start unity on machine boot up 0 Answers

I want to make the DepthImage of Kinect.V2 Renderer Mesh Skinned. 0 Answers

How to feed kinect v2 inside a sphere as point clouds in real-time 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges