Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Set your AiPath nodes with a texture  (Read 873 times)
beyonder
Moderator
Community Member
*****
Posts: 462


« on: December 31, 2010, 01:33:43 PM »

I thought of a good way to set my Ai path nodes. I'm using a texture. Check out the attached image.

All you do is create a 512x512 texture that parallels your landscape. Wherever you want a node you draw a single white pixel. It's good for placing nodes exactly where you want them to in your landscape. Here is the code - easily translatable to any language.

Code:
Public Sub MakeAiPathNodesTexture(AiTexture As Long)


     Dim minLandscapeVec As TV_3DVECTOR
     Dim maxLandscapeVec As TV_3DVECTOR
     
     Dim textureSize As Single
     
     Dim VectorArrayX(1000) As Single
     Dim VectorArrayZ(1000) As Single
   
     Dim HitCount As Long
     

textureSize = 512

Landscape.GetBoundingBox minLandscapeVec, maxLandscapeVec

Set AiPath = New TVAI
AiPath.InitNodeSystem
AiPath.SetNodeSystemParameters 1000, 500

Dim X1 As Long
Dim Y1 As Long
Dim TexVal1 As Long

Dim Red1 As Integer
Dim Green1 As Integer
Dim Blue1 As Integer

Dim LandToTextureRatio As Single

LandToTextureRatio = TVMath.GetDistance2D(minLandscapeVec.X, 0, maxLandscapeVec.X, 0) / textureSize

For X1 = 0 To textureSize - 1
For Y1 = 0 To textureSize - 1
TexVal1 = TVTextures.GetPixel(AiTexture, X1, Y1)
Long2RGB TexVal1, Red1, Green1, Blue1

If Red1 > 225 Then
VectorArrayX(HitCount) = minLandscapeVec.X + (X1 * LandToTextureRatio)
VectorArrayZ(HitCount) = minLandscapeVec.z + (Y1 * LandToTextureRatio)
HitCount = HitCount + 1
End If


Next Y1
Next X1

For i = 0 To HitCount

AiPath.AddNode VectorArrayX(i), 0, VectorArrayZ(i)
AiPath.EnableNode i, True
Next i

AiPath.CreateNodeGraph True
PathFinderEnable = True


End Sub
Logged

"And what I saw scared me to the depths of my miserable soul. It was true, it was all a sham, it ain't real." - The Thirteenth Floor
PaulTheAxeman
Community Member
*
Posts: 37


« Reply #1 on: January 02, 2011, 08:01:22 AM »

Nice. Thanks for that.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks