Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Game Object doesn't stay fixed in its place

yusufyusuf
edited January 2017 in Questions And Answers

Hello,

I'm procedurally generating a game object which is a map tile. Problem is, after the generation both in Unity and in HoloLens, object does not stay in its location but changes position relative to my head's location. Thus, I can't look at it from other angles or I can't get close to it. This doesn't happen on any other object and I couldn't find any related question on the web. Here is a video of the problem;

Note: Origami objects are there just for reference. They work without any issue.

https://youtu.be/Liv-zT4Q30w

Any help is greatly appreciated.

Thanks!

Tagged:

Best Answer

  • Options
    yusufyusuf
    edited February 2017 Answer ✓

    I ended up using another model with from-scratch Unity application, however, same problem occurred. I believe the problem was the size of the hologram. I decreased the size of my hologram to the size of the Origami stage, and it worked! Stayed fixed in the 3d world, and I was able to look around.

Answers

  • Options

    Silly question but is the object a child of the camera? Also follow up question, how is its position being modified? Maybe disable its update function to see if it happens.

    http://www.redsprocketstudio.com/
    Developer | Check out my new project blog

  • Options

    What behaviors are attached to the object? Seems like there may be a follow behavior on there that is enabled in editing mode.

    Taqtile

  • Options

    @AmerAmer Not at all! I appreciate the feedback and brainstorming.

    1) Object is not a child of the camera
    2) Update function is empty:

    // Update is called once per frame
        void Update() {
    
        }
    
  • Options

    @mark_grossnickle Thanks a lot for your comments!

    Here is the Inspector screenshot of the generated object:
    https://www.dropbox.com/s/2txbzz6p3u0g16l/TileRootReadySS.png?dl=0

    I generated this scene from another unity project, and I saved and embedded the parameters into my current Unity project so that I can recreate it. Can it be caused by that? Please see the parts start with;

    float[] surfaceVerts = { -306f, 0f, 307f,

    float[] items3 = { -306f, 218.7174f, 307f,

    And here is the full code;

    using Mapbox.Scripts.Utilities;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Xml.Serialization;
    using System.Linq;
    using UnityEngine;
    using System.Xml;
    using System;
    
    #if WINDOWS_UWP
    using Windows.Storage;
    using System.Threading.Tasks;
    using Windows.Data.Xml.Dom;
    using System;
    using System.Xml;
    #endif
    
    
    public class TileViewerReady : MonoBehaviour {
        private GameObject tileObject;
        private int tileResolution = 7;
    
        public TextAsset imageAsset;
        public Texture2D myGUITexture;
    
        public static string MeshFolderName
        {
            get
            {
    #if !UNITY_EDITOR
                return ApplicationData.Current.RoamingFolder.Path;
    #else
                    return Application.persistentDataPath;
    #endif
            }
        }
    
        [SerializeField]
        GameObject _tilePrefab;
        // Use this for initialization
        IEnumerator Start() {
            // tileObject = GameObject.Find("TileRootReady");
            tileObject = Instantiate(_tilePrefab);
            tileObject.name = "TileRootReady";
            Camera.main.transform.position += tileObject.transform.position;
            //var mf = tileObject.GetComponent<MeshFilter>();
    
            Vector3 temp = new Vector3(0.0f, -300.0f, 550f);
            tileObject.transform.position += temp;
    
            Vector3 temp2 = new Vector3(0.4f, 0.4f, 0.4f);
            tileObject.transform.localScale = temp2;
    
    
            var mesh = new Mesh();
            float[] surfaceVerts = { -306f, 0f, 307f, -306f, 0f, 205f, -306f, 0f, 103f, -306f, 0f,  ..ABOUT 50 MORE FLOATS HERE...-202.6667f , 305.5f, 0f, -304.5f  };
            var surfaceVector = new List<Vector3>();
            for (int i = 0; i < surfaceVerts.Length; i += 3)
            {
                Vector3 rowX = new Vector3(surfaceVerts[i], surfaceVerts[i + 1], surfaceVerts[i + 2]);
                surfaceVector.Add(rowX);
            }
            mesh.SetVertices(surfaceVector);
    
            var trilist = new List<int>();
            for (int y = 0; y < tileResolution - 1; y++)
            {
                for (int x = 0; x < tileResolution - 1; x++)
                {
                    trilist.Add((y * tileResolution) + x);
                    trilist.Add((y * tileResolution) + x + tileResolution);
                    trilist.Add((y * tileResolution) + x + tileResolution + 1);
    
                    trilist.Add((y * tileResolution) + x);
                    trilist.Add((y * tileResolution) + x + tileResolution + 1);
                    trilist.Add((y * tileResolution) + x + 1);
                }
            }
            mesh.SetTriangles(trilist, 0);
    
            var uvlist = new List<Vector2>();
            var step = 1f / (tileResolution - 1);
            for (int i = 0; i < tileResolution; i++)
            {
                for (int j = 0; j < tileResolution; j++)
                {
                    uvlist.Add(new Vector2(i * step, 1 - (j * step)));
                }
            }
            mesh.SetUVs(0, uvlist);
            mesh.RecalculateNormals();
    
            var mf = tileObject.GetComponent<MeshFilter>();
            mf.sharedMesh = mesh;
    
            var rend = tileObject.GetComponent<MeshRenderer>();
    
            Texture2D tex = new Texture2D(512, 512, TextureFormat.DXT5, false);
            byte[] imageData;
    
            WWW www = new WWW("http://s-iihr50.iihr.uiowa.edu/demir/knowledge/hololensmaps/SavedScreen.png");
            //Texture2D texTmp = new Texture2D(1024, 1024, TextureFormat.DXT1, false);
            //LoadImageIntoTexture compresses JPGs by DXT1 and PNGs by DXT5     
            yield return www;
            www.LoadImageIntoTexture(tex);
    
            // Texture2D mapTexture;
    
            var rend2 = tileObject.GetComponent<MeshRenderer>();
            rend2.material.mainTexture = tex;
    
            //tex.LoadImage(myGUITexture.Data);
    
            float[] items3 = { -306f, 218.7174f, 307f, -306f, 219.7213f, 205f, -306f, 217.1111f, ..ABOUT 50 MORE FLOATS HERE...170.8304f, -304.5f };
            var verts3 = new List<Vector3>();
            for (int i = 0; i < items3.Length; i += 3)
            {
                Vector3 rowX2 = new Vector3(items3[i], items3[i + 1], items3[i + 2]);
                verts3.Add(rowX2);
            }
    
            mf.mesh.SetVertices(verts3);
            mf.mesh.RecalculateNormals();
            mf.mesh.RecalculateBounds(); //Bunlar bina koordinatlari buyuk ihtimal
    
    
            //BuildVectorTile();
        }
    
  • Options
    yusufyusuf
    edited February 2017 Answer ✓

    I ended up using another model with from-scratch Unity application, however, same problem occurred. I believe the problem was the size of the hologram. I decreased the size of my hologram to the size of the Origami stage, and it worked! Stayed fixed in the 3d world, and I was able to look around.

Sign In or Register to comment.