Why is this identity script giveing uuid [zero] back as id?


#1

Bug ? Or user error, but this script example returns a zero 00000000-0000-0000-0000-000000000000 uuid instead of the model uuid. What am trying todo, place a model inworld. save the entitiyID for later use, but the id is not stored !

var pitch = 90.0;
var yaw = 0.0;
var roll = 180.0;
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll)

var originalProperties = {
    type: “Model”,
    position: { x: 133.0,
                y: 170.0,
                z: 137.0 },

dimensions: {     x: 2.0,
                            y: 2.0,
                            z: 2.0 },

color: { red: 0,
             green: 255,
             blue: 0 },

modelURL: “http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX”,

rotation: rotation
};

var entityID = Entities.addEntity(originalProperties);

print(entityID.id);

Whats wrong ?


#2

I see the same issue. I’m not sure that the model is actually a unique item when the final line is printed, but maybe it’s a bug.

I think we all need to help with documentation, there is very little documentation about entity properties.


#3

I played with this for some time and discovered this.
To retrieve the ID we use Entities.identifyEntity(originalProperties)
here is the same code that prints an ID.

This code will retrieve the ID,

var pitch = 90.0;
var yaw = 0.0;
var roll = 180.0;
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll)

var originalProperties = {
    type: "Model",
    position: { x: 133.0,
                y: 170.0,
                z: 137.0 },

        dimensions: {     x: 2.0,
                            y: 2.0,
                            z: 2.0 },                        

    color: { red: 0,
             green: 255,
             blue: 0 },

    modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX",

    rotation: rotation
};

var entityID = Entities.addEntity(originalProperties);
var number = Entities.identifyEntity(originalProperties);
print (number.id);

I even put in a bug report before I discovered this,
Entities.getEntityProperties() does not get the id but
Entities.identifyEntity() does get it.
So it seems the identity is separate from the properties.


#4

Thanks.@adrian :slight_smile: That seems to work. But sounds more complex then needed. We still not know wich one is right but going to use your way. I tried something else and that gave wrong uuid.

Note: Hmm no something go wrong again. i get 2 different uuid’s in my other script with the same object. Rge uuid i get back from the model is different compared to the uuid i get when you click the model and get the id with findRayIntersection. puzzled.


#6

@Richardus could you please post the script you are using to click the model and get the id, that would be useful for a few reasons.
Thx.


#7

Ok, still working on it so ther ecan be some weirdness in the code or messy.

//coordinates where the door get placed
var startpos = {x: 130, y: 168.25, z: 140};
var doorAngle = 90;
var doorIsOpen = false;
var doorEntityID;
var door_timer;
var newProperties;
var entityID;
var i = 0;

//start rotation of the door
var pitch = 0.0;
var yaw = 0.0;
var roll = 0.0;
rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);

//Place the door
function placeDoor()
{
    var originalProperties = 
    {
        type: "Model",
        modelURL: "http://assets.sqmv.nl/Hifi Door 007.fbx",
  
        position: { x: startpos.x,
                        y: startpos.y,
                        z: startpos.z },
                                
        dimensions: {     x: 0.05,
                            y: 2.10,
                            z: 1.00 },        

        color: { red: 255,
                    green: 255,
                    blue: 255 },
                 
        rotation:     rotation,
        
        registrationPoint: { x: 0.5, 
                                    y: 0.55, 
                                    z: 0.0 },
                 
        gravity: {     x: 0.00,
                        y: 0.00,
                        z: 0.00 },
                                
        lifetime: -1.0    
    }
    
    entityID = Entities.addEntity(originalProperties);
    doorEntityID = Entities.identifyEntity(originalProperties);        
    print("Rezz:"+doorEntityID.id);
}

function openDoor()
{
    do
    {
        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
        newProperties = 
        {
            rotation:     rotation,
        };    
        Entities.editEntity(doorEntityID, newProperties);

        i=i+0.01;
    }
    while (i <= doorAngle)
}

function  closeDoor()
{
    do
    {
        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
        newProperties = 
        {
            rotation:     rotation,
        };    
        Entities.editEntity(doorEntityID, newProperties);

        i=i-0.01;
    }
    while (i >= 0)
}

function mousePressEvent(event) 
{
   var pickRay = Camera.computePickRay(event.x, event.y);
   var intersection = Entities.findRayIntersection(pickRay);

    newModel = intersection.entityID;
    var identify = Entities.identifyEntity(newModel);
    
    print("--------------------");
    print("Rezz:"+doorEntityID.id);    
    print("Door:"+doorEntityID.id);
    print("Click:"+identify.id);
    print("--------------------");    

    if (identify.id==doorEntityID.id)
    {
        if (!doorIsOpen)
        {
            doorIsOpen=!doorIsOpen;
            openDoor();
        }
        else
        {
            doorIsOpen=!doorIsOpen;    
            closeDoor();
        }
    }
}

function scriptEnding() 
{ 
    Entities.deleteEntity(entityID);
}

Controller.mousePressEvent.connect(mousePressEvent);
Script.scriptEnding.connect(scriptEnding);

placeDoor()

//Script.stop();

#8

Smaller example. its seems i have model uuid, thats comeing from EntityID.id and when iam clicking the door i get a click model uuid identify.id the EntityID.id never seems to change, how many times im starting and stop the scriipts seems to make no difference. starting the script multipli times still gives always the same uuid back in EntityID.id, i would expect a different uuid. Entity properties return for every entity a different uuid.

So, why or how do i get the uuid from the entity i justy placed ? and not the model uuid.

//var foundIntersection = Entities.findRayIntersection(pickRay); (editmodels.js)
var startpos = {x: 130, y: 168.25, z: 140};

//start rotation of the door
var pitch = 0.0;
var yaw = 0.0;
var roll = 0.0;
rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);

var orginalentityID;

var originalProperties =
{
        type: “Model”,
        modelURL: “http://assets.sqmv.nl/Hifi Door 007.fbx”,

position: { x: startpos.x,
                        y: startpos.y,
                        z: startpos.z },

dimensions: {     x: 0.05,
                            y: 2.10,
                            z: 1.00 },

color: { red: 255,
                    green: 255,
                    blue: 255 },

rotation:     rotation,

registrationPoint: { x: 0.5,
                                    y: 0.55,
                                    z: 0.0 },

gravity: {     x: 0.00,
                        y: 0.00,
                        z: 0.00 },

lifetime: -1.0    
}

function mousePressEvent(event)
{
        var pickRay = Camera.computePickRay(event.x, event.y);
        var intersection = Entities.findRayIntersection(pickRay);

newModel = intersection.entityID;
          var identify = Entities.identifyEntity(newModel);

print(identify.id);
}

function scriptEnding()
{
    Entities.deleteEntity(orginalentityID);
}

Script.scriptEnding.connect(scriptEnding);
Controller.mousePressEvent.connect(mousePressEvent);

orginalentityID = Entities.addEntity(originalProperties);
var EntityID = Entities.identifyEntity(originalProperties);        
print(“Rezz:”+EntityID.id);


#9

Further more, no matter what model I import It seems to be given the same ID which is
491dd8f0-fd93-4c10-b5d1-de57ab83f03d
Rich’s door, my jeep, even items from Chris’s objects list all come in with the same ID

@Richardus what ID do you get when importing an entity?


#10

Good question, i dont import before i know the mesh is fine. Let’ me try. Short story, import models , cannot hahndle fbx. so i dont know how to upload a model. Trying model url now. And when i have uploaded the file,I would not know how to access it from the script. only know the way with url. :open_mouth: Also i need to place to mesh from the script, the mesh properties info you see on your screen are always different. @Adrian not sure waht you want, but afraid i cannot test it.


#11

Your first script does it, line 52   print(“Rezz:”+doorEntityID.id);
that seems to give the ID that I posted, every time, no matter which model I import, either by script (your script) or the import button, will give the same ID.
as soon as you run the script look at the consol, that is the first ID. note that down ( or open log file)

Then click on the door, and that should fire the lines 95 to 99 and give you a different ID.

But I want the ID that is given when you first run the script and the entity is added and first identified.


#12

Just logged in, open the log screen. run the script. and this happend more but always where thinking its script error. i get this.

014-09-22T19:16:09] Loading file: "h:/Scripts/Door.js"
[2014-09-22T19:16:09] Logging activity "loaded_script"
[2014-09-22T19:16:09] script:print()<< "Rezz:{00000000-0000-0000-0000-000000000000}"

Stopping the script and start it again, i see this.

[2014-09-22T19:17:33] stopping script... "h:/Scripts/Door.js"
[2014-09-22T19:17:35] QWindowsDialogHelperBase<class QPlatformFileDialogHelper>::nativeDialog invoked with no native dialog present.
[2014-09-22T19:17:37] Loading file: "h:/Scripts/Door.js"
[2014-09-22T19:17:37] Logging activity "loaded_script"
[2014-09-22T19:17:37] script:print()<< "Rezz:{0a1065a3-0f2d-493f-bebe-e302d9094797}"

Here the output from the script when i click the door.

[2014-09-22T19:21:10] script:print()<< "Angular size too big: 59.66818441574098"
[2014-09-22T19:21:10] script:print()<< "Rezz:{0a1065a3-0f2d-493f-bebe-e302d9094797}"
[2014-09-22T19:21:10] script:print()<< "Door:{0a1065a3-0f2d-493f-bebe-e302d9094797}"
[2014-09-22T19:21:10] script:print()<< "Click:{b4a236e5-b940-46c1-b262-a4851644ef21}"

think this what you want…


#13

Yes that is exactly what I want, although you produce a different rezz ID than me which should be no surprise.

This shows that the first time the script is loaded, the ID is not yet issued by the server and shows all zeros, but as Zappoman said, in this case all zeros is a workable ID as it will be the only object recognized by your script as all zeros.
Then when we call mousePressEvent(event) we get the registered ID.
this will be the same ID as we get when we turn on the (editModels.js) model selector and select an object, I found the ID given by the findRayIntersection mouse touch has changed from the originalProperties, which leads me to believe that the ID retrived by the raytrace is the correct one.

But I think the reason we get another different ID returned when we call doorEntityID is because it is giving us originalProperties, every time, and I think this is the token ID given by the viewer, because as you noted everytime the script is run, even with a different model, it will continue to return that original properties ID (which is no longer valid because we have changed from the original now.)

Testing…
Delete any old doors and stop the door script.
Have some other object inworld ready to click, with your editModels selector on, click the object and note the ID from the log.
Then run the door script, check the log, note the ID of the object that came in, if the script has changed from last run you will get all zeros. If the script hasnt changed you will get the same ID as last time.
Now click on the door,
What we get will be a click result from the editModels selector, and 3 results from your script, the first 2 IDs (“door” and “rezz”) will be the original properties ID and the last value (“Click”) should be the real ID which should match the ID returned by the editModels selector.

Finally if you click on the other object you will get its ID from the editModels selector
and from your script you will see the same old ID again twice as it returns the original properties of the script, but the last ID is the one from the raytrace which should be the same as the editModels one, proving it to be the correct one.

Please anyone feel free to correct me in any of this because this is not documentation, this is all guesswork, trial and error, perseverance and some faith.


#14

There seems to be some bugs happening here, bug report being thrashed out here https://worklist.net/20064

Here is some real information from ZappoMan
Quick explanation:

  1. The official UUID’s for entities are managed and assigned by the server. Only a server can assign an official UUID.

  2. The addEntity() method adds an entity locally AND sends an add command/request to the server. The client assigns an “EntityItemID” which is an opaque data structure which internals can change. But from an implementation perspective that “entity item id” contains 3 parts.

    a) the “is known ID” status - which indicates whether or not this client KNOWS the true identity of the entity (only possible after the server as authorized creation and informed the client of the true identity)

    b) the client creation token - this is a client assigned token which can be used in the client to edit/inspect/delete an entity which is currently in an “unknown” state.

    c) the official UUID (if known) - this will either be the empty UUID in cases where the ID is unknown, or it will be the server assigned UUID in cases where the ID is known. -

  3. It’s ALWAYS EXPECTED that addEntity() will return an Entity Item ID with an “is know” of FALSE and a UUID of all zeros. This is EXPECTED BEHAVIOR because the client creates the entity locally immediately, and then returns before the server can respond with an official UUID.

  4. You can continue to use the entity item id in the client and it should continue to edit, inspect, and delete the entity. An entity item ID with all zeros is NOT PER SE incorrect. So long as the entity item id was returned from a call to addEntity() that entity item ID will continue to be valid for operation throughout that client scripting session.

  5. However - you can also inspect the entity item id and determine if the server has returned an official UUID for the entity by using the identityEntity() method. This method takes an entity item ID, and returns a modified entity item id. Most of the example scripts use this feature to determine if the local entity has been approved by the
    server.


Entities.getEntityProperties() should work correctly on entity item IDs with known or unknown UUIDs. Looking at the code path, getEntityProperties() calls identifyEntity() internally, so they should operate identically.

That said, if it’s not working, we definitely would consider that a bug that needs to be fixed. If you can provide a repro-case that would be great.


#15

OK, with this code i can get the right ID

var properties = Entities.getEntityProperties(entityID);        
    doorEntityID = properties.id;
    print(“Rezz:”+doorEntityID);

But you cannot place this in “function placeDoor()” it returns zero uuid. Ok, make a seperate function is solveing that problem. But if i make a function like this. (i keep variable global for now)

function GetUUID()
{
    properties = Entities.getEntityProperties(entityID);        
    doorEntityID = properties.id;
    print(“Rezz:”+doorEntityID);    
}

works fine if its in the mousevent function. it fails when i place it in the placedoor() function. it also still returns a zero uuid if am placeing it after the call of the doorplace.

placeDoor();
GetUUID();

At least i have the door working so you need to click on the door. still somethings weird.

I hope that we can soon use soon function from other javascript you add. to the one you work on, thats so needed with this way of codeing. you really need to make you own function database and keep that in lets say unit you call. https://alphas.highfidelity.io/t/how-to-call-function-from-other-javascript/916 that would make porgramming more easy.


#16

Are you sure the enityID is in the correct scope ?

e.q. maybe you have to pass the entityID as a parameter of getUUID() function.


#17

Let me post the script how it works for me now. maby the past where from cleaned up code.
It works for me correct when i place “getRealModelId(entityID);” in the mouse event.
Bigger new problem, the mouse even dont work for other users, so the cannot open the door. Unless i need to run the script in different way. its now running from my desk in the client.

//
//  Door.js V0.01
//
//  Created by Richardus Raymaker on 23-09-2014.

//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

//coordinates where the door get placed
var startpos = {x: 130, y: 167, z: 140};
//doorsize
var doorsize = {x: 0.05, y: 2.10, z: 1.00 };

//Model location (URL)
modelUrl = "http://assets.sqmv.nl/Hifi Door 007.fbx";

//Angle the door open
var doorAngle = 90;

//Scrip[t parameters.
var doorSteps = 0.01;
var doorIsOpen = false;
var doorEntityID;
var entityID;
var i = 0;

//start rotation of the door
var pitch = 0.0;
var yaw = 0.0;
var roll = 0.0;
rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);

//Place the door
function placeDoor()
{
    var originalProperties = 
    {
        type: "Model",
        modelURL: modelUrl,
  
        position: { x: startpos.x,
                        y: startpos.y,
                        z: startpos.z },
                                
        dimensions: {     x: doorsize.x,
                            y: doorsize.y,
                            z: doorsize.z },        

        color: { red: 255,
                    green: 255,
                    blue: 255 },
                 
        rotation:     rotation,
        
        registrationPoint: { x: 0.5, 
                                    y: 0.0, 
                                    z: 0.0 },
                 
        gravity: {     x: 0.00,
                        y: 0.00,
                        z: 0.00 },
                                
        lifetime: -1.0    
    }
    
    var originalentityID = Entities.addEntity(originalProperties);
    return originalentityID;
}

//--Get the id from the placed model
function getRealModelId(ModelEntityID)
{
    var properties = Entities.getEntityProperties(ModelEntityID);        
    var propertiesEntityID = properties.id;
    return propertiesEntityID;
}

//--
function openDoor()
{
    do
    {
        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
        var newProperties = 
        {
            rotation:     rotation,
        };    
        Entities.editEntity(entityID, newProperties);

        i=i+doorSteps;
    }
    while (i <= doorAngle)
}

//--
function  closeDoor()
{
    do
    {
        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
        var newProperties = 
        {
            rotation:     rotation,
        };    
        Entities.editEntity(entityID, newProperties);

        i=i-doorSteps;
    }
    while (i >= 0)
}

//--
function mousePressEvent(event) 
{
    doorEntityID=getRealModelId(entityID);

   var pickRay = Camera.computePickRay(event.x, event.y);
   var intersection = Entities.findRayIntersection(pickRay);
    var newModel = intersection.entityID;
    var identify = Entities.identifyEntity(newModel);
    var doorIdentify=identify.id;

    if (doorIdentify==doorEntityID)
    {
        if (!doorIsOpen)
        {
            doorIsOpen=!doorIsOpen;
            openDoor();
        }
        else
        {
            doorIsOpen=!doorIsOpen;    
            closeDoor();
        }
    }
}

//--
function scriptEnding() 
{ 
    Entities.deleteEntity(entityID);
}

entityID=placeDoor();

Controller.mousePressEvent.connect(mousePressEvent);
Script.scriptEnding.connect(scriptEnding);

#18

@Atlante45. @chris told me to ask you. How can others open and close the door to ? MouseEvent seems not to work for others. Or do we not have any command for that available ?


#19

Hey @Richardus,

Well for that, they need to know about the same UUID you have in your script.
So the best way would instead be to check the URL/position of the entity instead and if you think it’s the right one, then open/close it.

Otherwise just create the door, get UUID and hardcode it in your script. The pb is, if the door gets deleted and you put it back, it’ll have a different UUID. So you’ll have to update all your script.


#20

The mouse event is only for the person who is running the script. We have not yet added a way for someone to click on something and get a signal back to another person’s script. Will consider!


#21

Ok. but you cannot read the mouse position in Script A from User B ?
So this need a complete different thinking, I have some idea. but it means that every user need toi run a door script to open en close a door at this moment. not that a door keep people outside right now. :grinning:

I go work on client side script, my approach where more thinking from the server side.
Still preffer the server side option, client side give other problems. But for now its good learning.