WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 02-09-2009, 11:57 AM
hosier hosier is offline
Member
 
Join Date: Feb 2007
Posts: 31
Lightwave objects rotation problem

Hello. I have a Lightwave model made up of 50+ objects. All of the objects in this model have a center point of [0,0,0] even though that isn't what I would consider their center of mass. As such, the objects aren't rotating around what would be their visible center.

The creator of the model doesn't know how to change this in his model, and has instead given me the coordinates for each object. Right now I've written a simple Vizard program to load the model and then use getChild to create a node variable for one of the objects. I've tried using the <node3d>.center function to change the pivit point for the object, but it still doesn't rotate around it.

Here's my program:
Code:
# import the required system functions
import viz


# start vizard
viz.go()

# Load the complete bovine model
bovine = viz.add('all_centered.lwo')

# Move our viewpoint
viz.MainView.setPosition(4,0,0)
viz.MainView.setEuler(-90,0,0)

# get a node for one muscle in the model
muscle = bovine.getChild('005')

#make the rest of the carcass transparent
bovine.alpha(0)
muscle.alpha(1)

# Marker to show new rotation point
MARKER = viz.add('ball.wrl')
MARKER.setScale(.25,.25,.25)
MARKER.setPosition(.0695,.0346,.7674)


print 'My Position: ',muscle.getPosition(viz.ABS_GLOBAL)
print 'My Orientation: ',muscle.getEuler(viz.ABS_GLOBAL)
print 'Muscle Center: ',muscle.getCenter()
print 'Marker Center: ',MARKER.getCenter()

muscle.center(.0695,.0346,.7674)

print 'My Position: ',muscle.getPosition(viz.ABS_GLOBAL)
print 'My Orientation: ',muscle.getEuler(viz.ABS_GLOBAL)
print 'Muscle Center: ',muscle.getCenter()
print 'Marker Center: ',MARKER.getCenter()



##############################################
## This function deals with keyboard events ##
##############################################
def mykeyboard(key):

	global muscle
	global MARKER
	
# rotate left
	if key == 'j':
		muscle.setEuler(5,0,0,viz.REL_GLOBAL)
		print "Muscle Center: ",muscle.getCenter()
		print "Muscle Position: ",muscle.getPosition()
		
# rotate right
	if key == 'k':
		muscle.setEuler(-5,0,0,viz.REL_GLOBAL)
		print "Muscle Center: ",muscle.getCenter()
		print "Muscle Position: ",muscle.getPosition()

# rotate up
	if key == 'i':
		muscle.setEuler(0,0,5,viz.REL_GLOBAL)
		print "Muscle Center: ",muscle.getCenter()
		print "Muscle Position: ",muscle.getPosition()

# rotate down
	if key == 'm':
		muscle.setEuler(0,0,-5,viz.REL_GLOBAL)
		print "Muscle Center: ",muscle.getCenter()
		print "Muscle Position: ",muscle.getPosition()



#######################################################################
viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
Am I missing something, or could it be because of the model? I can upload that if need be.

Thanks in advance for any help I can get.

Aaron
Reply With Quote
  #2  
Old 02-10-2009, 12:28 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
when you right click on your model in the resources window and then select properties and then navigate to your child object, is there another node under that?
Reply With Quote
  #3  
Old 02-11-2009, 09:45 AM
hosier hosier is offline
Member
 
Join Date: Feb 2007
Posts: 31
There are other nodes under that. I haven't talked to the model creator yet, but I think that there is a "front" and "back" for each object in the model. At least that's what it's starting to look like to me. The model is about 13MB, so instead of attaching it here, I've made it available to download here: http://quasar.unl.edu/all_centered.lwo

Will I have to set a center for each child object or is there a way of treating them as a whole.

Thanks.

Aaron
Reply With Quote
  #4  
Old 02-11-2009, 02:22 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
I was able to change the center by grabbing the node below the one you were using
Code:
muscle = model.getChild('005_bicepsfemoris_1M')
Sorry, I don't understand your question about setting the centers for each object or as a whole
Reply With Quote
  #5  
Old 02-12-2009, 06:06 AM
hosier hosier is offline
Member
 
Join Date: Feb 2007
Posts: 31
I was trying to set the center of the object above that, the 005 object, which represents the entire muscle. When I use muscle = model.getChild('005') and perform translations on it, it works like I think it should. When I perform the model.center on that object, that's when my rotations aren't around the new center of the object, even though it reports that the center has been set.

All of the muscles originally have an origin of [0,0,0] and a center of [0,0,0]. I then set the center of the selected muscle to the new rotation point, and the getCenter reports the proper value, but it doesn't rotate around it.

If you run my above program, you'll see that it selects the 005 child object then prints out its position and center. I set the new center, and again print out the information about the object, showing that the new center has been set. I earlier loaded the Vizard ball.wrl and placed it at this new center point. It does show up at what should be the center of the object. When you use the ijkm keys to rotate it, though, it does not rotate around this new center.

If I'm doing this the wrong way, please let me know, but from the documentation, it seems like this should work.

The part where I was talking about setting the center for each object or as a whole was in reference to the fact that each muscle is made up of two surfaces. In my case, I'm working with the 005 object, where you set the center for the 005_bicepsfemoris_1M, which is one surface of two making up the muscle.

Thanks in advance.

Aaron
Reply With Quote
  #6  
Old 02-13-2009, 11:32 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
When you specify a center, it will be set in the nodes local coordinate system. You will need to convert the pivot point from the models coordinate frame to the muscles local coordinate frame before setting the center. Here is a sample script that shows how to accomplish this:
Code:
import viz
viz.go()

#Add model
model = viz.add('all_centered.lwo')
bb = model.getBoundingSphere()

#Add environment
import vizshape
vizshape.addGrid(color=[0.2]*3)
viz.clearcolor(viz.GRAY)

#Setup camera navigation
import vizcam
cam = vizcam.PivotNavigate()
cam.setCenter(bb.center)
cam.setDistance(bb.radius*2)

#Rotation pivot point in models reference frame
PIVOT = [.0695,.0346,.7674]

#Display rotation pivot point as a green ball
anchor = vizshape.addSphere(radius=0.1,parent=model,color=viz.GREEN,pos=PIVOT)

#Get handle to muscle
muscle = model.getChild('005')

#Convert pivot point from model coordinate frame to local coordinate frame of muscle
localMatrix = muscle.getMatrix(viz.ABS_GLOBAL) * model.getMatrix(viz.ABS_GLOBAL).inverse()
muscle.setCenter(localMatrix * viz.Vector(PIVOT))

#Spin muscle
muscle.addAction(vizact.spin(1,0,0,90,viz.FOREVER))
Reply With Quote
  #7  
Old 02-13-2009, 12:04 PM
hosier hosier is offline
Member
 
Join Date: Feb 2007
Posts: 31
Thanks for your help on this. I had been working on this some more and had finally figured out about the same thing. I found out that while the muscles had a euler of [0,0,0] to the complete model, it was [-180,90,180] to the global world.

In my case I was able to multiply the y pivot point by -1 and then swap it with the z pivot point to provide the proper points.

Thanks for the supplied code. I'll add that into my repository of resources I've been building. It'll make things much easier in the future when they aren't quite as straightforward as this.

Aaron
Reply With Quote
Reply


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
export problem bazelaisr Vizard 2 05-28-2008 10:19 AM
rotation problem krimble Vizard 1 11-21-2007 10:22 AM
importing a single WRL with many objects. giancamati Vizard 3 12-18-2006 01:13 PM
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM
using Lightwave objects vorin Vizard 1 01-12-2005 10:15 AM


All times are GMT -7. The time now is 05:05 PM.


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