PDA

View Full Version : Point Helper and LookAt_Constraint()


sheefy
09-03-2006, 04:26 AM
Hey guys,

I've run into a little problem which I just don't understand. I'm trying to create a point helper and then add a look at constraint to it but keep getting an error when I do things a certain way.

Here's the code - btw, all variables have their values initialized by the time I call this and are all fine (in terms of point 3 values beig point 3 values, etc);


-- Function Start
fn CreateSplineControl SCName SCPosition SCTarget =
(
SControl = point cross:off centermarker:off box:on axistripod:off size:StubLength
SControl.position = SCPosition
SControl.name = SCName
SControl.wireColor = (color 154 215 229)

SControl.rotation.controller = LookAt_Constraint()
SControl.rotation.controller.appendTarget SCTarget 100
SControl.rotation.controller.viewline_length_abs = false
)-- End Function

--Call the Function
CreateSplineControl "CNTRL_UpperLegSpline" ChainVectorTop $P_Knee


I get an error saying "-- Unable to convert: Point to type: String" and the Maxscript listener highlights the first line in the function where I create the point and tell it how to display it.

so anyways i can get it to work by changing the first line from;

SControl = point cross:off centermarker:off box:on axistripod:off size:StubLength

To...

SControl = point cross:off box:on size:StubLength

I don't understand why this should work - I've checked and rechecked and everything seems to be spelt right. I've used a similar method before.

Mind you, I can leave the first line alone and get rid of the last line in the function and it works too...

SControl.rotation.controller.viewline_length_abs = false

But I need that property.

I'm still a novice at this and I would greatly appreciate why I'm running into problems. By the way, I'm using Max 8 SP3.

Also, It was working before on another computer at work running 8 SP3 and one running 7 SP1.

Cheers!
-sheefy

Wahooney
09-05-2006, 09:57 AM
Seems to work fine on my PC. Although I had to make some slight modifications, ie. defining ChainVectorTop and StubLength.

Could you post the code you use to assign these values please so that I can check if the problem doesn't lie there?

sheefy
09-05-2006, 12:38 PM
Thanks for looking at it Wahooney, much appreciated.

Here's the troublesome bit of code...I think the problem may lie in the function that creates the spline - as when I delete it everything seems to work. I have no idea why though and it's really annoying me.

Anyhoo, just create three point objects called - P_Hip P_Knee and P_Ankle - that should be all it needs.


( -- START SCRIPT --

-- Get Positions from Point Objects in Scene
local StartKnot = $P_Hip.pos
local MiddleKnot = $P_Knee.pos
local EndKnot = $P_Ankle.pos
-- Bone Properties
local BoneWidth = 5
local BoneHeight = 5
local StubLength = BoneWidth
local zAxis = [-1,0,0]

-- Find Vector
fn FindVector ChainStart ChainEnd =
(
v1 = ChainStart
v2 = ChainEnd
ChainVector = v2 - v1
)-- End Function

-- Create the Spline
fn CreateSpline SplineName StartCP EndCP SCPInVec SCPOutVec ECPInVec ECPOutVec =
(
ln = line()
splIdx = addNewSpline ln
-- Anchor / InVecHandle / OutVecHandle
addKnot ln splIdx #bezier #curve StartCP SCPInVec SCPOutVec
addKnot ln splIdx #bezier #curve EndCP ECPInVec ECPOutVec
updateShape ln
convertToSplineShape ln
ln.wireColor = (color 50 50 50)
ln.steps = 24
ln.name = SplineName
return ln
)-- End Function

-- Create Spline Control Handles
fn CreateSplineControl SCName SCPosition SCTarget =
(
SControl = point cross:off centermarker:off box:on axistripod:off size:StubLength
SControl.position = SCPosition
SControl.name = SCName
SControl.wireColor = (color 154 215 229)

SControl.rotation.controller = LookAt_Constraint()
SControl.rotation.controller.appendTarget SCTarget 100
SControl.rotation.controller.viewline_length_abs = false
)-- End Function

-- Clear MAXScript Listener
ClearListener()

-- Get the Position for Control Points
CPMultiplyer = .35
ChainVectorTop = FindVector EndKnot StartKnot
ChainVectorTop = (ChainVectorTop * CPMultiplyer) + MiddleKnot
ChainVectorBottom = FindVector EndKnot StartKnot
ChainVectorBottom = ((ChainVectorBottom * CPMultiplyer) * -1) + MiddleKnot

-- Draw Splines
CreateSpline "SPLN_UpperLeg" StartKnot MiddleKnot StartKnot StartKnot ChainVectorTop MiddleKnot
CreateSpline "SPLN_LowerLeg" MiddleKnot EndKnot MiddleKnot ChainVectorBottom EndKnot EndKnot

-- Create the Spline Handle
CreateSplineControl "CNTRL_UpperLegSpline" ChainVectorTop $P_Knee

) -- END SCRIPT --


Thanks again.
-sheefy

Wahooney
09-05-2006, 01:02 PM
Ok, I've had a good look at your code and I can tell you that this is singley the most bizarre bug I've ever encountered... I've experienced similar before, but this has just added a new level of odd, it just seems like the cosmos doesn't like your script.

My first recommendation is rewrite the code, there isn't a hell of a lot there so doing it should be about 10-15 minutes work. But, and I must stress this, don't refer back to your old code! If you just go into a copy and paste fest chances are that you'll probably end up copying and pating the code that's giving you hassles. Besides this way you'll doubtlessly end up writing a better piece of script, try using different variable names too.

If you really want to keep your old code I'd suggest adding "" beneath the last line of fn CreateSplineControl, don't ask my why but it seems to work.

I hope this helps.

sheefy
09-05-2006, 01:21 PM
HAHAHA, Cheers Wahooney, I was really hoping though that it was something really stupid that I had done.

I'm still quite new to this so would you be able to give me any simple pointers on improving my script...I don't mean as in re-write the code for me (i wanna figure that out myself). But maybe a few pointers of what areas could be written more efficiently and maybe what you mean by better naming for the variables.

Thanks again,
-S

Wahooney
09-05-2006, 01:25 PM
My pleasure sheefy,

Well, there are so many pointers out there that it would be difficult to know where to begin, if you ask me or anyone on this forum a specific question we'll be more than happy to help.

:thumbsup:

sheefy
09-05-2006, 01:29 PM
Ok Cheers,

I'll do a bit more research and re-write that block of code along with the rest and see how I go.

Thanks again for your help!

CGTalk Moderation
09-05-2006, 01:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.