forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   3D-программирование (http://forum.boolean.name/forumdisplay.php?f=12)
-   -   нужна функция (http://forum.boolean.name/showthread.php?t=16953)

ant0N 23.06.2012 11:02

нужна функция
 
Привет всем!
Помогите найти функцию для работы с каждым объектом на карте .CSM (Cartography Shop). Эта функция была в уроках от BlitzShool..

RBK 23.06.2012 17:20

Ответ: нужна функция
 
Вложений: 1
Этот файл?

ant0N 24.06.2012 09:49

Ответ: нужна функция
 
RBK, спасибо! этот тоже нужен :)
А вообще я про другую спрашивал. Когда я загружу сделанный в этом редакторе уровень, как я буду управлять отдельными объектами? Помню там нужно было с помощью ключей задавать имена, а потом функцией читать эти ключи... эта функция мне и нужна

L-ee-X 24.06.2012 17:34

Ответ: нужна функция
 
Вложений: 1

Код:

;=================================================
 ;=================================================
Function LoadCSM(file$,texturepath$=".\")

 f=ReadFile(file)
If Not f Return

ChangeDir FileDir(file)

 lightmapbank=CreateBank()
 texturebank=CreateBank()

;Version - this will load CShop 4.0 and CShop 4.1 maps
version=ReadInt(f)
If version<>4 And version<>5
  CloseFile f
  Return
EndIf

 map=CreatePivot()

;Groups
DebugLog groupcount+" groups"
groupcount=ReadInt(f)
For n=1 To groupcount
  flags=ReadInt(f)
  group=ReadInt(f)
  Properties$=readstringn(f)
  r=ReadInt(f)
  g=ReadInt(f)
  b=ReadInt(f)
Next

;Visgroups (new in 4.1)
If version=5
  visgroupcount=ReadInt(f)
  For n=1 To visgroupcount
      name$=readstringn(f)
      flags=ReadInt(f)
      r=ReadInt(f)
      g=ReadInt(f)
      b=ReadInt(f)
  Next
EndIf

;Lightmaps
 lightmapcount=ReadInt(f)
DebugLog lightmapcount+" lightmaps"
For n=1 To lightmapcount
  w=ReadInt(f)
  h=ReadInt(f)
  texture=CreateTexture(w,h)
  TextureCoords texture,1
  ResizeBank lightmapbank,BankSize(lightmapbank)+4
  PokeInt lightmapbank,BankSize(lightmapbank)-4,texture
  LockBuffer TextureBuffer(texture)
  For ty=0 To h-1
      For tx=0 To w-1
          hue=ReadInt(f)
          WritePixelFast tx,ty,hue,TextureBuffer(texture)
    Next
  Next
  UnlockBuffer TextureBuffer(texture)
Next

;Meshes
 meshcount=ReadInt(f)
DebugLog meshcount+" meshes"
For n=1 To meshcount
 flags=ReadInt(f)
 group=ReadInt(f)
 properties$=readstringn(f)
 r=ReadInt(f)
 g=ReadInt(f)
 b=ReadInt(f)
 x#=ReadFloat(f)
 y#=ReadFloat(f)
 z#=ReadFloat(f)

If version=5 visgroup=ReadInt(f)

 facecount=ReadInt(f)
DebugLog facecount+" surfaces."

 mesh=CreateMesh(map)
NameEntity mesh,properties
PositionEntity mesh,x,y,z

;Surfaces
For s=1 To facecount
 flags=ReadInt(f)
 texturefile$=readstringn(f)
 lightmapindex=ReadInt(f)
 offsetu#=ReadFloat(f)
 offsetv#=ReadFloat(f)
 scaleu#=ReadFloat(f)
 scalev#=ReadFloat(f)
 rotation#=ReadFloat(f)
 vertexcount=ReadInt(f)
DebugLog vertexcount+" vertices"
 trianglecount=ReadInt(f)
DebugLog trianglecount+" triangles"
 linecount=ReadInt(f)

 surf=CreateSurface(mesh)
 brush=CreateBrush()
 texturefile=Lower(texturefile)
 texture=retrievetexture(texturepath+texturefile,texturebank)
If texture BrushTexture brush,texture
If lightmapindex>0 And lightmapindex*4<=BankSize(lightmapbank)
 lightmap=PeekInt(lightmapbank,(lightmapindex-1)*4)
If lightmap
BrushTexture brush,lightmap,0,1
BrushFX brush,1
EndIf
EndIf
PaintSurface surf,brush
FreeBrush brush

;Vertices
For v=0 To vertexcount-1
 x#=ReadFloat(f)
 y#=ReadFloat(f)
 z#=ReadFloat(f)
 nx#=ReadFloat(f)
 ny#=ReadFloat(f)
 nz#=ReadFloat(f)
 r=ReadInt(f)
 g=ReadInt(f)
 b=ReadInt(f)
 u0#=ReadFloat(f)
 v0#=ReadFloat(f)
 w0#=ReadFloat(f)
 u1#=ReadFloat(f)
 v1#=ReadFloat(f)
 w1#=ReadFloat(f)

TFormPoint x,y,z,0,mesh
AddVertex surf,TFormedX(),TFormedY(),TFormedZ(),u0,-v0
VertexColor surf,v,r,g,b
VertexTexCoords surf,v,u1,-v1,0,1
VertexNormal surf,v,nx,ny,nz

Next

;Triangles
For t=0 To trianglecount-1
  a=ReadInt(f)
  b=ReadInt(f)
  c=ReadInt(f)
AddTriangle surf,a,c,b
Next

For l=0 To linecount-1
 a=ReadInt(f)
 b=ReadInt(f)
Next

Next
Next

;Point Entities
entitycount=ReadInt(f)
DebugLog entitycount+" entities"
For n=1 To entitycount
  visgroup=ReadInt(f)  ; used to be flags, but wasn't really used
  group=ReadInt(f)
  properties$=readstringn(f)
  x#=ReadFloat(f)
  y#=ReadFloat(f)
  z#=ReadFloat(f)
  entity=CreatePivot(map)
  NameEntity entity,properties
  PositionEntity entity,x,y,z
Next

;Free textures
For n=0 To BankSize(lightmapbank)-1 Step 4
  FreeTexture PeekInt(lightmapbank,n)
Next
FreeBank lightmapbank
For n=0 To BankSize(texturebank)-1 Step 8
  FreeBank PeekInt(texturebank,n)
  FreeTexture PeekInt(texturebank,n+4)
  Next
FreeBank texturebank

CloseFile f
Return map
End Function

;Read a null-terminated string
Function ReadStringN$(f,maxlength=0)
Repeat
  ch=ReadByte(f)
  If ch=0 Return t$
  If maxlength
  If Len(t$)=maxlength Return t$+Chr(ch)
  EndIf
  t$=t$+Chr$(ch)
Forever
End Function


;Return a loaded texture
Function RetrieveTexture(file$,bank)
For n=0 To BankSize(bank)-1 Step 8
  namebank=PeekInt(bank,n)
  s$=""
  For b=0 To BankSize(namebank)-1
    s=s+Chr(PeekByte(namebank,b))
  Next
  If s=file Return PeekInt(bank,n+4)
Next
ResizeBank bank,BankSize(bank)+8
 namebank=CreateBank(Len(file))
For b=0 To BankSize(namebank)-1
  PokeByte namebank,b,Asc(Mid(file,b+1))
Next
DebugLog "Loading texture "+file
PokeInt bank,BankSize(bank)-8,namebank
 texture=LoadTexture(file)
If Not texture DebugLog "Failed to load texture "+Chr(34)+CurrentDir()+file+Chr(34)
PokeInt bank,BankSize(bank)-4,texture
Return texture
End Function


;Get the file part of a file path
Function FileName$(file$,ext=1)
 file=Replace(file,"/","\")
Repeat
 p=Instr(file,"\")
If p
 file=Right(file,Len(file)-p)
Else
Exit
EndIf
Forever
If Not ext
 p=Instr(file,".")
If p file=Left(file,p-1)
EndIf
Return file
End Function

;Get the directory of a file path
Function FileDir$(file$)
 file=Replace(file,"/","\")
 oldp=1
Repeat
 p=Instr(file,"\",oldp)
If p
 oldp=p+1
Else
 file=Left(file,oldp-1)
Exit
EndIf
Forever
Return file
End Function

;Parsing function
Function Piece$(s$,entry,char$=" ")
While Instr(s,char+char)
 s=Replace(s,char+char,char)
Wend
For n=1 To entry-1
 p=Instr(s,char)
 s=Right(s,Len(s)-p)
Next
 p=Instr(s,char)
If p<1
 a$=s
Else
 a=Left(s,p-1)
EndIf
Return a
End Function

;Function for retrieving entity properties
 ;[ "light"=KeyValue(entity,"classname") ]
Function KeyValue$(entity,key$)
 properties$=EntityName(entity)
 key$=Lower(key)
Repeat
 p=Instr(properties,Chr(10))
If p test$=(Left(properties,p-1)) Else test=properties
 testkey$=Piece(test,1,"=")
 testkey=Trim(testkey)
 testkey=Replace(testkey,Chr(34),"")
 testkey=Lower(testkey)
If testkey=key
 value$=Piece(test,2,"=")
 value$=Trim(value$)
 value$=Replace(value$,Chr(34),"")
Return value
EndIf
If Not p Return
 properties=Right(properties,Len(properties)-p)
Forever
End Function


Вот сам урок, почитай!

ant0N 26.06.2012 11:56

Ответ: нужна функция
 
L-ee-X, спасибо! почитаю


Часовой пояс GMT +4, время: 07:33.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot