Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Newcomer
Posted
Hello All,

This is my first post as I just downloaded this program three days ago. Anyway I have a few scripts that I would like to add to the community. I have a question about scripting as well. I always like to give something in return for help/advice so I will post the following two scripts in hopes that somebody could do me a favor and answer my question in return.

The first Script creates a flag object of user defined height, width and density. The default settings are set to create a 400 face rectangle that can then be set to animate with the second Component Script.

Language = VBScript

'*********************************************************************************
' Purpose: Create a Ripple or a Flag (will it doesn't ripple yet)
' Created by Seth Cohen
'*********************************************************************************

Option Explicit 'require variable declarations

Sub Main (CanvasApp)

Dim Scene 'The current active scene
Dim SceneRootGroup 'The root Group of the scene
Dim Group 'The Group for our object (face)
Dim Object 'The object we are creating (face)
Dim Face 'The face we are creating
Dim NumFaces 'Number of faces = (numfacesX-1)*(numfacesY-1)
Dim GridOriginX 'The 3D Canvas Grid's Origin (x)
Dim GridOriginY 'The 3D Canvas Grid's Origin (y)
Dim GridOriginZ 'The 3D Canvas Grid's Origin (z)
Dim GridSize 'The 3D Canvas Grid's Size
Dim GridInterval 'The 3D Canvas Grid's Interval

Dim Width 'User defined Width
Dim Height 'User defined Height
Dim xdensity 'number of points in the x direction
Dim ydensity 'number of points in the y direction
Dim nWidth 'User defined nWidth
Dim nHeight 'User defined nHeight

Dim FirstPointX 'First point in face
Dim FirstPointY 'First point in face
Dim FirstPointZ 'First point in face
Dim AxisX 'Axis to rotate the start position around
Dim AxisY 'Axis to rotate the start position around
Dim AxisZ 'Axis to rotate the start position around
Dim NewPointX 'Point to add
Dim NewPointY 'Point to add
Dim NewPointZ 'Point to add

Dim x 'Loops
Dim y 'Loops

Dim BoxMinX 'The Object's Bounding Box
Dim BoxMinY 'The Object's Bounding Box
Dim BoxMinZ 'The Object's Bounding Box
Dim BoxMaxX 'The Object's Bounding Box
Dim BoxMaxY 'The Object's Bounding Box
Dim BoxMaxZ 'The Object's Bounding Box
Dim Material 'The Face's Material


'What Dimensions should the flag have?
Do
Width = InputBox("What is the Width of the Flag/Ripple",,"4")
Height = InputBox("What is the Height of the Flag/Ripple",,"3")
xdensity = InputBox("What x density would you like",,"20")
ydensity = InputBox("What y density would you like",,"20")

'if they entered anything
If Width <> "" And xdensity <> "" Then
'they could have entered anything so ensure it is valid
On Error Resume Next

If Height <> "" And ydensity <> "" Then
On Error Resume Next

nWidth = clng(Width)
Err.Clear
On Error Goto 0

nHeight = clng(Height)
Err.Clear
On Error Goto 0

End If
End if
Loop Until nWidth > 0 And nHeight > 0 And xdensity > 0 And ydensity > 0

'If they entered anything continue
If nWidth > 0 And nHeight >0 And xdensity > 0 And ydensity > 0 Then

'get the scene
Set Scene = CanvasApp.GetActiveScene

'get the root Group
Set SceneRootGroup = Scene.GetRootGroup

'create a Group for the object (Flag)
Set Group = Scene.CreateGroup

'add it to the scene
SceneRootGroup.AddChild Group

'give the Group a name - note that we can't do this
'until the Group is added to the scene
Group.SetName "Flag Group"

'create an object
Set Object = Scene.CreateObject()


'add a dummy normal to the object (we need one to add the points)
Object.AddNormal 0,0,-1

'add the points to the object
For y = 0 to ydensity - 1
For x = 0 to xdensity - 1
NewPointX = x*nWidth/xdensity
NewPointY = y*nHeight/ydensity
NewPointZ = 0

'add the NewPoint to the object
Object.AddPoint NewPointX, NewPointY, NewPointZ

Next
Next

'add from bottom left to top right
For y = 0 to ydensity - 2
For x = 0 to xdensity -2

'Create a face to add to the Flag
Set Face = Object.CreateFace()

'add points and normals to face
Face.AddPointAndNormal x + y*xdensity,0
Face.AddPointAndNormal x + (y+1)*xdensity,0
Face.AddPointAndNormal x + (y+1)*xdensity + 1,0
Face.AddPointAndNormal x + y*xdensity + 1,0

'Create an appropriate material for the face
Set Material = Scene.CreateMaterial

'make it a nice color
Material.SetColor .250,.700,.250

'set the default diffuse value
Material.SetDiffuse 60

'set the default ambient value
Material.SetAmbient 20

'make the material opaque
Material.SetTranslucent 0

'apply the material to the face
Face.SetMaterial Material

Next
Next

'add the object to the created Group
'this also triggers the update to the database
Group.AddObject Object

'set the object name - note that we can't do this until
'the object is added to a Group
Object.SetName "Flag"

'Now that we know the size of the object let's set the position of the Group
'so the face is visible

'get the 3D Canvs grid details
CanvasApp.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval

'get the object's dimensions
Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ

'Center the Object's Group on the Scene and have the object sitting nicely
'on the surface
Group.SetPosition SceneRootGroup, 0, GridOriginX + GridSize / 2, GridOriginY - BoxMinY, GridOriginZ + GridSize /2

End If
End Sub



************************************************************
'Purpose: To create a ripple or flag on a multi-faced plane
'Created by: Seth Cohen
************************************************************
Language = VBScript

Sub AnimateObject (Time, CanvasObject)
Dim PointCount
Dim PointIndex
Dim PointX
Dim PointY
Dim PointZ
Dim MinX
Dim MinY
Dim MinZ
Dim MaxX
Dim MaxY
Dim MaxZ
Dim epicenterX
Dim epicenterY
Dim DistanceX
Dim DistanceY
Dim Distance 'Distance from point to epicenter

'Get bounding box to position epicenter relative to object
CanvasObject.GetBoundingBox MinX,MinY,MinZ,MaxX,MaxY,MaxZ

'get the number of points in the object
PointCount = CanvasObject.GetPointCount

'Set epicenter in the middle of object to make a ripple
'and off to side for a flag
'Adjust scale to change wavelength
'play around with these values and find some really neat things
epicenterX = (MaxX + MinX)/2
epicenterY = (MaxY + MinY)/2

'Run through the points scaling them
For PointIndex = 0 to PointCount - 1

'get the point
CanvasObject.GetPoint PointIndex, PointX, PointY, PointZ

'Calculate distance from epicenter to point

'adjust the "7" to alter wavelength
DistanceX = (PointX - epicenterX)*7
DistanceY = (PointY - epicenterY)*7
Distance = sqr(DistanceX*DistanceX + DistanceY*DistanceY) + .5*Time

PointZ = .125*sin(Distance)

'set the point
CanvasObject.SetPoint PointIndex, PointX, PointY, PointZ

Next

End Sub

****************************************************************
 
Posts: 5 | Registered: Tue December 20 2005Reply With QuoteEdit or Delete MessageReport This Post
Newcomer
Posted Hide Post
Sorry for putting everyone through that. The formatting did not come out quite as I had expected.

If there is a correct way to write code to screen I could attempt to fix that.

Well, my question is this. Is there anyway that I could combine those two scripts into one script that I can create and apply the animation to an object?

I am assuming that I would be able to do it with a .dll, but I do not know VB all that well. I really only know a little C++, but I plan to look at the samples soon.

Any help is appreciated.
Thanks
-Seth
 
Posts: 5 | Registered: Tue December 20 2005Reply With QuoteEdit or Delete MessageReport This Post
Newcomer
Posted Hide Post
Oh yeah, for some reason I have to go into materials and "reset to standard settings" before running the "make flag script" if I want my material to be anything other than a black mirror. Why is this?

Sorry for all of the questions but this program is great and I can't stay away from it Smile.

-Seth
 
Posts: 5 | Registered: Tue December 20 2005Reply With QuoteEdit or Delete MessageReport This Post
Newcomer
Posted Hide Post
Thanks anyway... I got it to work in a Plug-In.

I also updated it so you can create various geometries and have the ripple in a random pattern (more like a real flag or falling piece of paper)

If anyone wants to take a look I can post it. I would just post it right now but (judging from the overwhelming response this thread has received so far) I don't think anyone has even looked at this so I will wait for someone to ask for it.
 
Posts: 5 | Registered: Tue December 20 2005Reply With QuoteEdit or Delete MessageReport This Post
Newcomer
Posted Hide Post
Yeah, I'm interested. This could be very useful. Smile
 
Posts: 5 | Location: Canada | Registered: Wed March 16 2005Reply With QuoteEdit or Delete MessageReport This Post
Newcomer
Posted Hide Post
I'm interested. I hope this works out.

EDIT: I just ran the scripts on my machine. That's great! I really hope that you will be able to continue working on it.

3D
 
Posts: 14 | Registered: Fri March 05 2004Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 


© Amabilis Software 2003-2007