WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-30-2012, 02:02 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Axis Coordinates from Inspector

I am having a little trouble finding the axis relative to the global coordinate system of an object from within Vizard. When I get the handle for the object in question, and try to get the coordinates, I see that it should be perpendicular to the global axis.

Code:
screw.getAxisAngle(mode=viz.ABS_GLOBAL)
[-1.0, -0.0, 0.0, 90.0]
The information I am interested in finding is the angle of the straight line coordinate system relative to the global coordinate system as shown in the attached screenshot of inspector below. Is this the Normal angle of the object? It's obviously available in inspector, I'm just wracking my brain trying to figure out what it is in Vizard.
Attached Thumbnails
Click image for larger version

Name:	Screw_Axis.png
Views:	518
Size:	43.8 KB
ID:	520  
__________________
Reply With Quote
  #2  
Old 08-31-2012, 03:34 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
The axes in Inspector contains the accumulated transform of the selected node path. You can find the equivalent transform by calling:
Code:
xform = node.getMatrix(viz.ABS_GLOBAL,node='name')
Where name is the name of the selected node in Inspector for which you want to retrieve the axis transform from.

I just noticed that this command won't work if the name refers to a leaf (drawable) node. This will be fixed in the next release though.
Reply With Quote
  #3  
Old 09-05-2012, 09:51 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
That's exactly what I'm looking for. Thanks.
__________________
Reply With Quote
  #4  
Old 09-07-2012, 07:50 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
So to follow up, I've been able to reproduce the coordinate system in inspector. However, I am now trying to move that screw along one of the axis of that coordinate system by doing the following:

Code:
moveaction = vizact.moveTo(y_trans,time = 1.0, mode = viz.ABS_GLOBAL)
screw.addAction(moveaction)
The point y_trans refers to is the endpoint of the green axis in the attached photos. As you can see by the second photo, the screw does not get moved to the end of the green Axis. Is viz.ABS_GLOBAL the wrong mode to use with this command? Or am I just referring to the wrong coordinate system?
Attached Thumbnails
Click image for larger version

Name:	axis.png
Views:	456
Size:	431.2 KB
ID:	521   Click image for larger version

Name:	translate.png
Views:	448
Size:	146.0 KB
ID:	522  
__________________
Reply With Quote
  #5  
Old 09-07-2012, 10:56 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
No, you will want to use the default viz.ABS_PARENT mode, since you want the screw to move along its local axes.

How are you getting a handle to the screw object in Vizard? Are you using the getChild command?
Reply With Quote
  #6  
Old 09-10-2012, 06:17 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
I am calling the <node3d>.getChildren() function from the parent object.
__________________
Reply With Quote
  #7  
Old 09-11-2012, 08:53 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
I'm not sure if it's clear on what I'm trying to do. The first attached picture contains two coordinate axis drawn on the screw. The first one replicates the coordinate system that is created in inspector with axis colored red, green and blue. The second coordinate system shares its origin with the first, but is drawn to represent the global x,y,z coordinate system.

The basis for the first coordinate system is from the matrix created from the command:

Code:
<node3d>.getMatrix(viz.ABS_GLOBAL, node='Inst-1430')
[ 0.000000, -0.004384, -0.008988, 0.000000,
  -0.000000, 0.008988, -0.004384, 0.000000,
  0.010000, 0.000000, 0.000000, 0.000000,
  -0.381762, -0.560596, -2.557960, 1.000000 ]
So the x-coordinate is drawn by creating a vector using the 4th and 1st row of this matrix and scaled (just so they are visible). And the y (elements 5-7 of the matrix) and z (elements 9-11 of the matrix) coordinates are created using a similar method.

Code:
[-0.381762 + 0.0,  -0.560596 + (-0.004384), -2.557960 + (-0.008988)]
So the point I used to create the y coordinate is called y_trans.
I made the assumption that using the command

Code:
moveaction = vizact.moveTo(y_trans, mode = viz.ABS_GLOBAL)
<node3d>.addAction(moveaction)
Would move the screw to the endpoint of the green axis. Instead, that command moves the screw to the position shown in the second attachment. Is this because the transformation matrix given by the getMatrix command is applied to the node before the translation of the moveTo command?

Here is the complete code I am using to draw those axis:

Code:
def draw_line(p, axis, color):
	viz.startLayer(viz.LINES)
	viz.lineWidth(3)
	viz.vertexColor(color)
	viz.vertex(p)
	viz.vertex(axis)
	viz.endLayer()
	
def debug_script():
	#Data is a helper class that creates a global object to share all of our object data between scripts
        part = Data.getData().parts_list[0]
       	global screw
	screw = part.getChildren()[0]
	point = [-0.381762, -0.560596, -2.557960]
	x_axis = [ 0.000000, -0.004384, -0.008988]
	y_axis = [  -0.000000, 0.008988, -0.004384]
	z_axis = [ -0.01, -0.00, 0.00]
	
	x_global = [1.0, 0.0, 0.0]
	y_global = [0.0, 1.0, 0.0]
	z_global = [0.0, 0.0, 1.0]
	
	global x_trans
	x_trans = [point[i] + x_axis[i]*30 for i in range(3)]
	global y_trans
	y_trans = [point[i] + y_axis[i]*30 for i in range(3)]
	global z_trans
	z_trans = [point[i] + z_axis[i]*30 for i in range(3)]
	
	draw_line(point, x_trans, [1,0,0])
	draw_line(point, y_trans, [0,1,0])
	draw_line(point, z_trans, [0,0,1])
	
	x_global_axis = [point[i] + x_global[i] for i in range(3)]
	y_global_axis = [point[i] + y_global[i] for i in range(3)]
	z_global_axis = [point[i] + z_global[i] for i in range(3)]
	
	draw_line(point, x_global_axis, [1,1,0])
	draw_line(point, y_global_axis, [1,0,1])
	draw_line(point, z_global_axis, [0,1,1])
Attached Thumbnails
Click image for larger version

Name:	local_global_axis.png
Views:	453
Size:	297.6 KB
ID:	524   Click image for larger version

Name:	rel_global.png
Views:	433
Size:	202.0 KB
ID:	525  
__________________
Reply With Quote
  #8  
Old 09-11-2012, 09:11 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
There is not enough information for me to say what the problem is. My guess is you are applying the transformation at the wrong hierarchy in the scene. node.getChildren will not return anything unless you previously called node.getChild or parented a node to the object. So it's not clear to me exactly which node you are operating on.

Click on the screw you want to translate in Inspector, then post a screenshot of the node path bar at the top, showing the full hierarchy of the screw. This should provide me with enough information to post some sample code for you.
Reply With Quote
  #9  
Old 09-11-2012, 11:38 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Here is the screen cap you requested.
Attached Thumbnails
Click image for larger version

Name:	inspector_path.png
Views:	470
Size:	81.1 KB
ID:	526  
__________________
Reply With Quote
  #10  
Old 09-11-2012, 11:49 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Thanks. The following code should translate the screw object along its local Y-axis:
Code:
screw = model.insertGroupBelow('Inst-1430')
screw.setPosition([0,0.1,0])
This works by inserting a node below the Inst-1430 node. If you had called getChild on the node, it would have inserted a transform above the node, which would then translate the node in the incorrect reference frame.

Make sure you only call insertGroupBelow once per sub-node, since each call will insert a new node.
Reply With Quote
  #11  
Old 09-11-2012, 12:32 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
That appears to be what I am looking for. Thank you for your patience and help with this.
__________________
Reply With Quote
  #12  
Old 09-24-2012, 02:03 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Quick question regarding the nodes created by the insertGroupBelow command. I'm finding that these nodes seem to be immutable. Is there a reason for that?
__________________
Reply With Quote
  #13  
Old 09-24-2012, 02:20 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
To clarify, I have a node n:

sub_n = n.insertGroupBelow(<nodename>)

So when I want to add an attribute to sub_n like:

sub_n.parentNode = n

I cannot access that parentNode attribute.
__________________
Reply With Quote
  #14  
Old 09-25-2012, 08:16 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
It's still not clear what the problem is. Are you getting a Python exception when trying to set an attribute? If so, what is the error? Can you post some sample code that reproduces the error?

The following code works correctly for me:
Code:
model = viz.addChild('gallery.osgb')
group = model.insertGroupBelow('gallery')
group.myattribute = 'some value'
print group.myattribute
Reply With Quote
  #15  
Old 09-25-2012, 09:13 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Definitely. Sorry for lack of information.

The problem seems to be that when I call insertGroupBelow on a node, that group replaces the node.

So here is what I'm doing:

Code:
	sub_instance = p.insertGroupBelow(subnode)
	sub_instance.parentNode = p.instanceName
        ''' this copies defined properties from the parent node to the sub node '''
	CADParser.copyParams(p, sub_instance)
	sub_instance.inCollide = []
The meat of the copyParams code looks like this:

Code:
def copyParams(src,dst):
	dst.instanceNumber = src.instanceNumber
	dst.instanceName = src.instanceName
	dst.partNumber = src.partNumber
	dst.anarkParent = src
	src.anarkGroup = True
	dst.anarkGroup = True
	param_list = ["anarkFreeMovement"
				, "anarkTrans"
				, "anarkRotate"
				, "anarkRehomePos"
				, "anarkRehomeOri"
				, "anarkDependency"
				, "anarkColor"
				, "anarkAlpha"
				, "anarkBackface"
				, "anarkShader"
				, "anarkDescription"
				, "anarkImage"
				, "anarkModule"
				, "anarkLocal"
				, "anarkTool"
				, "layerSpacing"
				, "anarkRequires"
				, "anarkModRotate"
				, "anarkRev"
				]

	for param in param_list:
		if hasattr(src, param):
			exec("dst." + param + " = src." + param)
		else:
			try:
				exec("del dst." + param)
			except:
				pass
	
	if hasattr(dst, "anarkColor"):
		src.color(dst.anarkColor)

	if hasattr(dst, "anarkShader"):
		if dst.anarkShader == "smoothmetal":
			reflect = viz.add('image2.jpg')
			dst.texture(reflect,'',1)
			dst.appearance(viz.TEXGEN,'',1)
	
	if hasattr(dst, "anarkRotate"):
		src.rotatingParent = dst
In another module, when I've got the handle on one of these groups created with the insertGroupBelow, I get an exception when trying to access a parameter like:

Code:
'''Only executed when this part has been marked as being an inserted group'''
print part.anarkParent
I get an exception saying that the attribute does not exist.
__________________
Reply With Quote
  #16  
Old 09-25-2012, 09:46 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Because I can no longer edit my post,

Remove the code

Code:
	else:
			try:
				exec("del dst." + param)
			except:
				pass
From my previous post.
__________________
Reply With Quote
  #17  
Old 09-25-2012, 10:53 AM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
It is turning out to be that the part handle I thought was the group I created, is not the part I'm accessing in the other script.

I'm doing more digging to get the correct part handle.
__________________
Reply With Quote
  #18  
Old 09-25-2012, 01:09 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
And not having the correct part handle was indeed the case. Thanks again Farshizzo.
__________________
Reply With Quote
  #19  
Old 10-24-2012, 12:32 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
Re-opening the issue

I've come across some special cases here where we have parts that are modeled using multiple meshes. I would like to grab the handle of the highlighted part in the inspector picture, and move it along it's local coordinate axis. When I use the method of grabbing the two sub instances and move them the same distance along their coordinate axis, the behavior in the second attached picture is observed.
Attached Thumbnails
Click image for larger version

Name:	multi_screw.png
Views:	442
Size:	233.2 KB
ID:	542   Click image for larger version

Name:	Seperated_screw.png
Views:	435
Size:	31.2 KB
ID:	543  
__________________
Reply With Quote
  #20  
Old 11-05-2012, 01:27 PM
nabrahamson nabrahamson is offline
Member
 
Join Date: Sep 2011
Posts: 36
I tried re-creating this issue without all of my extra code libraries, and was unable to. When I dug further, I found that the parts were being moved multiple times at different levels of the hierarchy.


In short, this issue is resolved.
__________________
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Haptic touch texture coordinates yth Vizard 0 06-02-2012 03:40 AM
How do coordinates in IS900 thransform into coordinates in vizard's world jacky Vizard 1 08-11-2011 10:44 AM
child-objects in VRML-file all have the same coordinates Sven Vizard 4 06-09-2010 02:07 AM
viz.vertex coordinates lilio Vizard 6 05-16-2009 04:36 PM
Object rotating around world axis, not own axis tacbob Vizard 1 02-15-2007 09:12 AM


All times are GMT -7. The time now is 11:35 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC