Here are some functions which will deform a mesh in real-time. You can use them to blow stuff up, and simulate car crashes, etc.
Unfortunately, it does not yet support limbs, due to the missing command: Make mesh from limb
Also, it requires the matrix_utils plugin, or you have to write your own find free mesh() function
edit:
DEMO PROGRAM! (includes 1 extra function)
sync on
make object sphere 1,100,50,50
set object cull 1,0
ID as dword
ID = SetupDeformableObject(1,1)
autocam off
make object sphere 2,5
color object 1,rgb(255,0,0)
color object 2,0
do
start = timer()
text 0,0,"Use arrowkeys to move bomb on the x/z plane."
text 0,20,"Use ctrl/shift to move bomb vertically."
text 0,40,"Press space detonate bomb."
move object 2,upkey()-downkey()
move object right 2,rightkey()-leftkey()
move object up 2,shiftkey()-controlkey()
if spacekey() and detonate = 0
make object sphere 3,5
make object sphere 4,7
disable object zdepth 4
position object 3,object position x(2),object position y(2),object position z(2)
position object 4,object position x(2),object position y(2),object position z(2)
color object 3,rgb(255,0,0)
color object 4,rgb(255,255,0)
detonate = 1
endif
if inkey$() = "p"
paused = not paused
while inkey$() <> ""
sync
endwhile
endif
if detonate > 0 and paused = 0
position camera 0,0,0
turn camera left 0.5
move camera -200
scale object 3,200+detonate,200+detonate,200+detonate
scale object 4,detonate,detonate,detonate
ghost object on 3
ghost object on 4
inc detonate,20
SphereDestroyFaces(ID, object position x(3),object position y(3),object position z(3),0,0,0,object size x(3,1)/2)
ApplySpherePushDeformation(ID, object position x(4),object position y(4),object position z(4),object size x(4,1)/2)
if detonate > 1000
detonate = 0
delete object 3
delete object 4
endif
endif
repeat
until start+20<timer()
sync
loop
function SetupDeformableObject(ObjNum as dword, MemNum as dword)
ID as dword
MeshNum = find free mesh()
make mesh from object MeshNum,ObjNum
make memblock from mesh MemNum,MeshNum
delete mesh MeshNum
ID = make memory(8)
*ID = ObjNum
inc ID,4
*ID = MemNum
dec ID,4
endfunction ID
function SphereDestroyFaces(ID as dword, X as float, Y as float, Z as float, Xpos as float, Ypos as float, Zpos as float, Radius as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
Xo as float
Yo as float
Zo as float
Dist = Radius*Radius
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
for i = 12 to VertN step StepN
inc n
if n > 2 then n = 0
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
Xo = X-Xp
Yo = Y-Yp
Zo = Z-Zp
if ((Xo*Xo)+(Yo*Yo)+(Zo*Zo)<=Dist)
Xp = Xpos
Yp = Ypos
Zp = Zpos
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
write memblock float MemNum,i+off1,Xp
write memblock float MemNum,i+off1+4,Yp
write memblock float MemNum,i+off1+8,Zp
write memblock float MemNum,i+off2,Xp
write memblock float MemNum,i+off2+4,Yp
write memblock float MemNum,i+off2+8,Zp
write memblock float MemNum,i+off3,Xp
write memblock float MemNum,i+off3+4,Yp
write memblock float MemNum,i+off3+8,Zp
endif
next i
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function ApplySpherePushDeformation(ID as dword, X as float, Y as float, Z as float, Radius as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
Xo as float
Yo as float
Zo as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Dist = Radius*Radius
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
for i = 12 to VertN step StepN
inc n
if n > 2 then n = 0
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
Xo = Xp-X
Yo = Yp-Y
Zo = Zp-Z
if ((Xo*Xo)+(Yo*Yo)+(Zo*Zo)<=Dist)
d# = Radius/sqrt((Xo*Xo)+(Yo*Yo)+(Zo*Zo))
Xmo = Xo*d#
Ymo = Yo*d#
Zmo = Zo*d#
Xp = X+Xmo
Yp = Y+Ymo
Zp = Z+Zmo
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
endif
next i
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
Here are the current functions:
ID as dword = SetupDeformableObject(ObjNum as dword, MemNum as dword)
ObjNum as dword = RemoveDeformableObject(ID as dword)
ApplySphereStickyDeformation(ID as dword, X as float, Y as float, Z as float, Xmo as float, Ymo as float, Zmo as float, Radius as float)
ApplySpherePushDeformation(ID as dword, X as float, Y as float, Z as float, Radius as float)
PositionVertexA(ID as dword, X as float, Y as float, Z as float, Xpos as float, Ypos as float, Zpos as float, Near as float)
PositionVertexB(ID as dword, Vertex as dword, Xpos as float, Ypos as float, Zpos as float)
OffsetVertexB(ID as dword, Vertex as dword, Xmo as float, Ymo as float, Zmo as float)
Number as dword = GetObjectNumber(ID as dword)
Number as dword = GetObjectMemblock(ID as dword)
FindObjectLocalCoords(ID as dword, X as float, Y as float, Z as float)
Result as float = GetObjectLocalCoordX(ID as dword)
Result as float = GetObjectLocalCoordY(ID as dword)
Result as float = GetObjectLocalCoordZ(ID as dword)
Here is a definition of each parameter:
ID as dword : Unique ID of deformable object, must be stored in a dword variable.
ObjNum as dword : Object Number.
MemNum as dword : Memblock Number to store mesh data.
X,Y,Z as float : Position where deforming happens.
Xmo/Ymo/Zmo as float : Direction of deformation.
Radius : Radius of deformation sphere.
Here is a definition of each function:
SetupDeformableObject : Must be called on an object prior to first deformation. Returns the ID needed to reference the object.
RemoveDeformableObject : Frees all memory created with SetupDeformableObject
ApplySphereStickyDeformation : Pushes all vertices within sphere in the direction of deformation
ApplySpherePushDeformation : Pushes all vertices out of the sphere in their current angle from the center of the sphere.
PositionVertexA : Positions all vertices within a sphere at a point
PositionVertexB : Positions a single verticex at a point
OffsetVertexB : Offsets a single verticex
GetObjectNumber : Gets object number from ID
GetObjectMemblock : Gets memblock number from ID
FindObjectLocalCoords : Transforms world coords into local coords (requires ezrotate)
GetObjectLocalCoordX : Retrieves X value from FindObjectLocalCoords (requires ezrotate)
GetObjectLocalCoordY : Retrieves Y value from FindObjectLocalCoords (requires ezrotate)
GetObjectLocalCoordZ : Retrieves Z value from FindObjectLocalCoords (requires ezrotate)
Functions working on:
ApplySimplePlaneDeformation : Push all vertices in front of a plane.
ApplyComplexPlaneDeformation : Push all vertices in a custom direction if a plane goes through them.
ApplySimpleCircleDeformation : Push all vertices in front of a circle.
ApplyComplexCircleDeformation : Push all vertices in a custom direction if a circle goes through them.
For me to complete those four functions, I need someone to answer my question in
THIS thread.
And finally, here is the code:
UPDATED WITH NINE NEW FUNCTIONS!
function SetupDeformableObject(ObjNum as dword, MemNum as dword)
ID as dword
MeshNum = find free mesh()
make mesh from object MeshNum,ObjNum
make memblock from mesh MemNum,MeshNum
delete mesh MeshNum
ID = make memory(8)
*ID = ObjNum
inc ID,4
*ID = MemNum
dec ID,4
endfunction ID
function RemoveDeformableObject(ID as dword)
ObjNum as dword
MemNum as dword
ObjNum = *ID
inc ID,4
MemNum = *ID
delete memory ID-4
delete memblock MemNum
endfunction ObjNum
function ApplySphereStickyDeformation(ID as dword, X as float, Y as float, Z as float, Xmo as float, Ymo as float, Zmo as float, Radius as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
Xo as float
Yo as float
Zo as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Xmo = Xmo * 1.02
Ymo = Ymo * 1.02
Zmo = Zmo * 1.02
Dist = Radius*Radius
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
for i = 12 to VertN step StepN
inc n
if n > 2 then n = 0
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
Xo = X-Xp
Yo = Y-Yp
Zo = Z-Zp
if ((Xo*Xo)+(Yo*Yo)+(Zo*Zo)<=Dist)
inc Xp,Xmo
inc Yp,Ymo
inc Zp,Zmo
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
endif
next i
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function ApplySpherePushDeformation(ID as dword, X as float, Y as float, Z as float, Radius as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
Xo as float
Yo as float
Zo as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Dist = Radius*Radius
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
for i = 12 to VertN step StepN
inc n
if n > 2 then n = 0
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
Xo = Xp-X
Yo = Yp-Y
Zo = Zp-Z
if ((Xo*Xo)+(Yo*Yo)+(Zo*Zo)<=Dist)
d# = Radius/sqrt((Xo*Xo)+(Yo*Yo)+(Zo*Zo))
Xmo = Xo*d#
Ymo = Yo*d#
Zmo = Zo*d#
Xp = X+Xmo
Yp = Y+Ymo
Zp = Z+Zmo
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
endif
next i
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function PositionVertexA(ID as dword, X as float, Y as float, Z as float, Xpos as float, Ypos as float, Zpos as float, Near as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
Xo as float
Yo as float
Zo as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Dist = Near*Near
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
for i = 12 to VertN step StepN
inc n
if n > 2 then n = 0
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
Xo = X-Xp
Yo = Y-Yp
Zo = Z-Zp
if ((Xo*Xo)+(Yo*Yo)+(Zo*Zo)<=Dist)
Xp = Xpos
Yp = Ypos
Zp = Zpos
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
endif
next i
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function PositionVertexB(ID as dword, Vertex as dword, Xpos as float, Ypos as float, Zpos as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Dist = Near*Near
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
i = (Vertex*VertN)+12
n = i MOD 3
Xp = Xpos
Yp = Ypos
Zp = Zpos
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function OffsetVertexB(ID as dword, Vertex as dword, Xmo as float, Ymo as float, Zmo as float)
ObjNum as dword
MemNum as dword
Dist as float
Xp as float
Yp as float
Zp as float
local dim CalcVerts(18000) as dword
local dim FaceIndex(18000) as byte
VCC as integer
VCC = -1
Dist = Near*Near
MeshNum = find free mesh()
ObjNum = *ID
inc ID,4
MemNum = *ID
StepN = memblock dword(MemNum,4)
VertN = ((memblock dword(MemNum,8)-1)*StepN)+12
n = -1
i = (Vertex*VertN)+12
n = i MOD 3
Xp = memblock float(MemNum,i)
Yp = memblock float(MemNum,i+4)
Zp = memblock float(MemNum,i+8)
inc Xp,Xmo
inc Yp,Ymo
inc Zp,Zmo
write memblock float MemNum,i,Xp
write memblock float MemNum,i+4,Yp
write memblock float MemNum,i+8,Zp
inc VCC
CalcVerts(VCC) = i
FaceIndex(VCC) = n
REM Now calculate post deformation vertices
REM (Only ones of altered faces)
for a = 0 to VCC
i = CalcVerts(a)
n = FaceIndex(a)
rem GET TRIANGLE'S VERTICES
select n
case 0
off1 = 0
off2 = StepN
off3 = StepN+StepN
endcase
case 1
off1 = 0-StepN
off2 = 0
off3 = StepN
endcase
case 2
off1 = 0-(StepN+StepN)
off2 = 0-StepN
off3 = 0
endcase
endselect
VX1# = memblock float(MemNum,i+off1)
VY1# = memblock float(MemNum,i+off1+4)
VZ1# = memblock float(MemNum,i+off1+8)
VX2# = memblock float(MemNum,i+off2)
VY2# = memblock float(MemNum,i+off2+4)
VZ2# = memblock float(MemNum,i+off2+8)
VX3# = memblock float(MemNum,i+off3)
VY3# = memblock float(MemNum,i+off3+4)
VZ3# = memblock float(MemNum,i+off3+8)
AX# = VX1#-VX3#
AY# = VY1#-VY3#
AZ# = VZ1#-VZ3#
BX# = VX2#-VX1#
BY# = VY2#-VY1#
BZ# = VZ2#-VZ1#
NX# = (AY# * BZ#) - (AZ# * BY#)
NY# = (AZ# * BX#) - (AX# * BZ#)
NZ# = (AX# * BY#) - (AY# * ax)
NT# = sqrt(NX#*NX#+NY#*NY#+NZ#*NZ#)
NX# = NX#/NT#
NY# = NY#/NT#
NZ# = NZ#/NT#
write memblock float MemNum,i+off1+12,NX#
write memblock float MemNum,i+off1+16,NY#
write memblock float MemNum,i+off1+20,NZ#
write memblock float MemNum,i+off2+12,NX#
write memblock float MemNum,i+off2+16,NY#
write memblock float MemNum,i+off2+20,NZ#
write memblock float MemNum,i+off3+12,NX#
write memblock float MemNum,i+off3+16,NY#
write memblock float MemNum,i+off3+20,NZ#
next a
make mesh from memblock MeshNum,MemNum
change mesh ObjNum,0,MeshNum
delete mesh MeshNum
endfunction
function GetObjectNumber(ID as dword)
Number as dword
Number = *ID
endfunction Number
function GetObjectMemblock(ID as dword)
Number as dword
inc ID,4
Number = *ID
endfunction Number
function FindObjectLocalCoords(ID as dword, X as float, Y as float, Z as float)
Obj = *ID
ezro_seteuler object angle x(Obj),object angle y(Obj),object angle z(Obj)
ezro_findoffsetfrompoint X-object position x(Obj),Y-object position y(Obj),Z-object position z(Obj)
endfunction
function GetObjectLocalCoordX(ID as dword)
Obj = *ID
Result# = (ezro_getoffsetx()/(object size x(Obj,1)/object size x(Obj,0)))
endfunction Result#
function GetObjectLocalCoordY(ID as dword)
Obj = *ID
Result# = (ezro_getoffsety()/(object size y(Obj,1)/object size y(Obj,0)))
endfunction Result#
function GetObjectLocalCoordZ(ID as dword)
Obj = *ID
Result# = (ezro_getoffsetz()/(object size z(Obj,1)/object size z(Obj,0)))
endfunction Result#
If you use these, or like them, then please post here! It will be much appreciated
Enjoy!