home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 15
/
CD_ASCQ_15_070894.iso
/
vrac
/
dxf23dv1.zip
/
DXF23DV.ASM
< prev
next >
Wrap
Assembly Source File
|
1994-05-25
|
60KB
|
2,262 lines
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; DXF to 3DVectors Converter by John McCarthy
;
; Current DXF types supported: 3DFACE, PFACE
;
; The 3dfaces are between 1 and 4 points where:
; 1 = single point
; 2 = line
; 3 = triangle
; 4 = quadagon (?)
;
; Whereas the PFACE performs the same function but can be a mesh up to:
; 1 to 100 vertexes (see maxpolyline below)
; 1 to 2000 connections (see maxconns below)
; 1 to 3000 surfaces (see maxsurfs below)
;
;Options:
;
;DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]
;
; -x x translation for object (before scale) - can be floating point, +z = up
; -y y translation for object (before scale) - can be floating point, +z = up
; -z z translation for object (before scale) - can be floating point, +z = up
; -s scale factor - can be floating point
; -u x translation for object (after scale) - integer only, +y = down
; -v y translation for object (after scale) - integer only, +y = down
; -w z translation for object (after scale) - integer only, +y = down
; -m materials list filename (corresponds to layer names)
; -l selective layer processing (only process layers that are found
; in materials file)
; -n output true calculated surface normal (otherwise 0,0,0), useless option
; -q negate Y output axis
;
; I you have trouble assigning a material to a line it may be because the
; layer that the line is on has the shading option. Lines do not have
; surface normals and therefore cannot have the shading option set.
; If DXF23DV finds this occurance, it will insert a default texture that
; has no shading texture. eg: 0,0,colour,0
;
; If your a total knumbskull (like me) and you get ACAD's co-ordinate
; system messed up (like me) you can use the -q option to negate the Y
; axis and reverse the orientation of the polygons.
;
; Do not use punctuation in your material names or layer names.
; A # sign in the materials means a comment
;
; Using the PFACE allows ACAD to assign polygons with more than 4 surfaces.
; This removes the need for polygon optimization and gives greater control
; over the implementation of surfaces.
;
; The ACAD layer name is matched up with a materials file to give each surface
; a seperate surface type/colour/whatever. Surfaces can be selected through
; AutoCAD to be double sided, shaded, sine waved, or anything the user wants
; simply by nameing a new layer and assigning those surfaces to that layer.
; The materials file can then be edited/added in order to obtain the results
; the user desires.
;
; Sample materials file follows:
;
; # This is a comment
; # There must be 5 fields in each assigned texture!!
;
; CONSTANT 0,0,0,colour0,0
; SHADED 0,shade,0,colour1,0
; SINE 0,wavey,0,colour2,0
; BOTHSIDES both,0,0,colour3,0
; BOTHSHADE both,shade,0,colour4,0
; DOUBLESIDED double,0,0,colour5a,colour5b
; DOUBLESHADE double,shade,shade,colour6a,colour6b
; 1SHADE2SINE 0,shade,wavey,colour7a,colour7b
; 1SINE2SHADE 0,wavey,shade,colour8a,colour8b
; 2SINE double,wavey,wavey,colour9a,colour9b
; SAMPLESIDE this is,an example,of what,you can,do!
;
; Make sure your 3DFACEs and PFACEs are entered in Counter-Clockwise order!
;
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Link this with PMODE, FILE, and ARGC
.386p
jumps
code32 segment para public use32
assume cs:code32, ds:code32, ss:code32
include pmode.inc
include file.inc
include argc.inc
public _main
matbufsize = 1500 ; materials list buffer size
yes = 1
no = 0
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Macros
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
upper macro regx ; make register uppercase
local strl
cmp regx,"a"
jb short strl
cmp regx,"z"
ja short strl
sub regx,"a"-"A"
strl:
endm
imul32 macro regx
imul regx
shld edx,eax,1
inc edx
shr edx,1
movsx eax,dx
endm
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; DATA
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
inputname db 60 dup (?)
outputname db 60 dup (?)
buffer db 60 dup (?)
nx dd 0 ; translation of location
ny dd 0
nz dd 0
scale dd 0 ; overall scale done after move
nu dd 0 ; translation of location after scale
nv dd 0
nw dd 0
fileloc dd 0 ; current location in DXF file (offset)
dxfo dd 0 ; start dxf file location
dxfsize dd 0 ; dxf filesize
mato dd 0 ; materials file location
matsize dd 0 ; materials file size
materials dd 0 ; materials/layer names offset
hugestack dd 0 ; 4 gig stack location (_himembase)
maxpoints = 3000 ; max number of unique points in any DXF
maxconns = 2000 ; maximum connections
maxpolyline = 100 ; maximum pface verticies
ox = 0 ; offsets for points (from conmem)
oy = ox+maxpoints*4
oz = oy+maxpoints*4
sd = oz+maxconns*4 ; polygon number
p1 = sd+maxconns*4 ; point 1
p2 = p1+maxconns*4 ; point 2
wg = p2+maxconns*4 ; where going
wc = wg+maxconns*4 ; where came
ea = wc+maxconns*4 ; a,b,c,d of plane equation
eb = ea+maxconns*4
ec = eb+maxconns*4
ed = ec+maxconns*4
mt = ed+maxconns*4 ; texture/layer name
sn = mt+((maxconns+1)*4)/3 ; surface number (for sorting)
memoryneeded = maxpoints*4+oy+oz+sd+p1+p2+wg+wc+ea+eb+ec+ed+mt+sn
connmem dd 0 ; memory for points/connection data
points dd 0 ; number of points
surfaces dd 0 ; number of surfaces
connections dd 0 ; number of connections
thismaterial dd 0 ; current/working material
iterate db 0 ; flag to use iteration
layer db 0 ; flag for selective layer processing
tnormal db 0 ; flag for true surface normal output
yneg db 0 ; flag for y negation
temp1 dd 0
temp2 dd 0
temp3 dd 0
polyindex dd maxpolyline dup (0)
start dd 0
startconn dd 0
pvertexs dd 0
pfaces dd 0
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; CODE
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
include extras.rt
errmsg0 db 10,13,'Missing Filename!',0dh,0ah,"$"
errmsg1 db 10,13,'Not Enough Memory!',0dh,0ah,"$"
errmsg2 db 10,13,'Error Opening File!',0dh,0ah,"$"
errmsg3 db 10,13,'Error Loading Materials File!',0dh,0ah,"$"
errmsg4 db 10,13,'Error:Too Many Points in DXF!',0dh,0ah,"$"
errmsg5 db 10,13,'Error:No 3DFACEs or PFACEs Found in DXF!',0dh,0ah,"$"
errmsg6 db 10,13,'Dont Know How To Handle Parts Of This DXF!',0dh,0ah,"$"
okmsg db 10,13,"AutoCAD .DXF to 3DVECTORS converter by John McCarthy V0.1"
db 10,13,"DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]",10,13
db 10,13," -x x translation for object (before scale) - can be floating point, +z = up"
db 10,13," -y y translation for object (before scale) - can be floating point, +z = up"
db 10,13," -z z translation for object (before scale) - can be floating point, +z = up"
db 10,13," -s scale factor - can be floating point"
db 10,13," -u x translation for object (after scale) - integer only, +y = down"
db 10,13," -v y translation for object (after scale) - integer only, +y = down"
db 10,13," -w z translation for object (after scale) - integer only, +y = down"
db 10,13," -m materials list filename (corresponds to layer names)"
db 10,13," -l selective layer processing (only process layers that are found"
db 10,13," in materials file)"
db 10,13," -n output true calculated surface normal (otherwise 0,0,0), useless option"
db 10,13," -q negate Y output axis",10,13
db 10,13,"Use 3DFACE and PFACE to define your ACAD object."
db 10,13,"Enter your 3DFACEs and PFACEs in Counter-Clockwise order."
db 10,13,"BRIAN.MCCARTHY@CANREM.COM",10,13,"$"
exiterr0:
mov edx,offset errmsg0
call _putdosmsg
jmp okerr0
exiterr1:
mov edx,offset errmsg1
call _putdosmsg
jmp okerr0
exiterr2:
mov edx,offset errmsg2
call _putdosmsg
jmp okerr0
exiterr3:
mov edx,offset errmsg3
call _putdosmsg
jmp okerr0
exiterr4:
mov edx,offset errmsg4
call _putdosmsg
jmp okerr0
exiterr5:
mov edx,offset errmsg5
call _putdosmsg
jmp okerr0
exiterr6:
mov edx,offset errmsg6
call _putdosmsg
jmp okerr0
okerr0:
mov edx,offset okmsg
call _putdosmsg
jmp _exit
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Allocate memory
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
_main:
call _setbuf
mov eax,matbufsize ; allocate memory for materials
call _getmem
jc exiterr1
mov materials,eax
mov edi,eax
mov ecx,matbufsize/4 ; wipe materials buffer
xor eax,eax
rep stosd
mov eax,memoryneeded
call _getmem
jc exiterr1
mov connmem,eax
mov edi,eax
mov ecx,memoryneeded
xor eax,eax
rep stosb
mov points,eax
mov surfaces,eax
mov connections,eax
mov esi,_himembase ; 4gig stack!
mov hugestack,esi
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Parse and open DXF, allocate memory, load DXF, close file
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
xor al,al
mov edx,offset inputname
call _cchekstr
jc exiterr0
mov edx,offset inputname
call _openfile
jc exiterr2
call _filesize
mov dxfsize,eax
call _getlomem
jc exiterr1
mov dxfo,eax
mov edx,eax
mov ecx,dxfsize
call _readfile
jc exiterr2
call _closefile
mov edx,dxfo
mov ecx,dxfsize
call replace
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Parse and open materials file, allocate memory, load file, close file
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov matsize,0
mov al,"m" ; check for filename on commandline
mov edx,offset buffer
call _ccheksstr
jc nomaters
mov edx,offset buffer
call _openfile
jc exiterr3
call _filesize
mov matsize,eax
call _getmem
jc exiterr1
mov mato,eax
mov edx,eax
mov ecx,matsize
call _readfile
jc exiterr3
call _closefile
mov edx,mato
mov ecx,matsize
call replace
nomaters:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Parse and open output filename
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov al,1 ; check for filename on commandline
mov edx,offset outputname
call _cchekstr
jc exiterr0
mov edx,offset outputname
call _createfile
jc exiterr0
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Get scaling factor for points
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov scale,1*65536
mov al,"s"
mov edx,offset buffer
call _ccheksstr
jc noscale
mov edx,offset buffer
mov eax,dword ptr buffer
call _get_float32
mov scale,eax
noscale:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Get position offset for points
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov nx,0
mov al,"x"
mov edx,offset buffer
call _ccheksstr
jc nox
mov edx,offset buffer
call _get_float32
mov nx,eax
nox:
mov ny,0
mov al,"y"
mov edx,offset buffer
call _ccheksstr
jc noy
mov edx,offset buffer
call _get_float32
mov ny,eax
noy:
mov nz,0
mov al,"z"
mov edx,offset buffer
call _ccheksstr
jc noz
mov edx,offset buffer
call _get_float32
mov nz,eax
noz:
mov nu,0
mov al,"u"
mov edx,offset buffer
call _ccheksstr
jc nou
mov edx,offset buffer
call _strhtn
call _vct32
mov nu,eax
nou:
mov nv,0
mov al,"v"
mov edx,offset buffer
call _ccheksstr
jc nov
mov edx,offset buffer
call _strhtn
call _vct32
mov nv,eax
nov:
mov nw,0
mov al,"w"
mov edx,offset buffer
call _ccheksstr
jc now
mov edx,offset buffer
call _strhtn
call _vct32
mov nw,eax
now:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Hunt for -i iteration option
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov iterate,no
mov al,"i"
call _cchekswitchnc
jc yesiterate
mov iterate,yes
yesiterate:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Hunt for -l selective layer option
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov layer,no
mov al,"l"
call _cchekswitchnc
jc yeslayer
mov layer,yes
yeslayer:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Hunt for -q y negation option
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov yneg,no
mov al,"q"
call _cchekswitchnc
jc yesneg
mov yneg,yes
yesneg:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Hunt for -n normal output
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov tnormal,no
mov al,"n"
call _cchekswitchnc
jc yesnormal
mov tnormal,yes
yesnormal:
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Split DXF into single connection data, calc normals, assign materials
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
mov eax,dxfo
mov fileloc,eax
call dxf_3dfaces
mov eax,dxfo
mov fileloc,eax
call dxf_polylines
cmp surfaces,0
jz exiterr5
;call optimize
call renumber_surfaces
call collect_points
;call number_them
;call wipe_d
;call sort_them
call output_file
call _closefile
jmp _exit
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search for and (if neccessary) build materials list
; In:
; EDX => materials string (layer name) eg db "OBJECT1 "
; Out:
; EAX = assigned material number
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
assign_material:
mov esi,materials
mov edi,edx
xor ebp,ebp
amloopb:
cmp byte ptr [esi],0 ; test if at end of list => add on to list
je amaddit
amloop:
mov al,[esi] ; check if material is already in list
mov bl,[edi]
inc esi
inc edi
mov cl,al
or cl,bl
jz amout
cmp al,bl
je amloop
amout:
dec esi
cmp al,0
jne amabort
cmp bl,"0"
jae amabortx
mov eax,ebp ; material already present, return number
ret
amaddit:
mov al,[edx] ; material not found at all, add to list
mov [esi],al
inc edx
inc esi
cmp al,"0"
jae amaddit
xor al,al
mov [esi-1],al
mov eax,ebp
ret
amabort:
inc esi ; material not found, continue checking
cmp byte ptr [esi],0
jne amabort
amabortx:
inc esi
inc ebp
mov edi,edx
jmp amloopb
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Find material number ECX
; In: ECX = material number to find
; Out: EDX => location of material name (name only, use this to find material in file)
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
find_ecx:
mov edx,materials
cmp ecx,0
je _ret
mcxb:
inc edx
cmp byte ptr [edx],0
jne mcxb
loop mcxb
inc edx
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Unpad string
; In: EDX => string eg " , Hello th"
; Out: EDX => string (after spaces, colons, whatever) eg "Hello th"
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
unpad:
dec edx
upx:
inc edx
mov al,[edx]
cmp al,"-"
je upretx
cmp al,"."
je upretx
cmp al,"#"
je upretx
cmp al,"A"
jae upretx
cmp al,"9"
ja upx
cmp al,"0"
jb upx
upretx:
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Next string
; In: EDX => string eg "Hello there mi"
; Out: EDX => next string (after spaces, colons, whatever) eg "there mi"
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
next:
call unpad
dec edx
nxc:
inc edx
mov al,[edx]
cmp al,"-"
je nxc
cmp al,"#"
je nxc
cmp al,"A"
jae nxc
cmp al,"9"
ja nxretc
cmp al,"0"
jae nxc
nxretc:
jmp unpad
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search_string: Find string at EDX in DXF file
; In:
; EDX => ASCIIZ string to search for (DXF)
; EDI = location to start search
; EBP = location to end search
; Out:
; CF = 1 - not found
; CF = 0 - found
; EDI = location where found
; Notes: String at EDI must have a space or zero at end for search tp succeed.
; eg: EDX => "HELLO",0
; EDI => "ABCDHELLOEFGI" will FAIL! - but " ABCDHELLO DKJ" will succeed!
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
search_string:
mov esi,edx
mov ecx,edi
ssloop:
mov al,[esi]
mov ah,[ecx]
upper al
upper ah
inc esi
inc ecx
mov bl,al
or bl,ah
jz ssout
cmp al,ah
je ssloop
cmp al,0
jne ssabort
cmp ah,"0"
jae ssabort
ssout:
clc
ret
ssabort:
cmp ecx,ebp
jae ssretx
inc edi
jmp search_string
ssretx:
stc
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search materials file for information on material ECX
; In: ECX = material number to look for
; Out: EDX => string containing surface information (terminated with db 0,0)
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
find_info:
cmp matsize,0
je fidodefault
call find_ecx
mov esi,edx
mov edx,mato
filoop:
call unpad
xor ebx,ebx
ficx:
mov al,[esi+ebx]
mov ah,[edx]
upper al
upper ah
inc ebx
inc edx
cmp al,ah
je ficx
cmp al,0
je fifoundm
dec edx
fifinddol:
inc edx
cmp byte ptr [edx],0
jne fifinddol
mov eax,mato
add eax,matsize
cmp edx,eax
jb filoop
fidodefault:
mov edx,offset fidefault
ret
fifoundm:
dec edx
mov al,[edx]
cmp al,"A"
ja fifinddol
cmp al,"9"
ja unpad
cmp al,"0"
jae fifinddol
jmp unpad
fidefault db "0,shade,0,colour,0",0 ; for regular faces
fidefaull db "0,0,0,colour,0",0 ; for lines
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search line for "shade"
; In: EDX => string containing surface information (terminated with db 0,0)
; Out: CF = 0 shade found, CF = 1 shade not found EDX = ?
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
find_shade:
mov al,[edx]
cmp al,0
je fsnoshade
inc edx
upper al
cmp al,"S"
jne find_shade
mov al,[edx+0]
upper al
cmp al,"H"
jne find_shade
mov al,[edx+1]
upper al
cmp al,"A"
jne find_shade
mov al,[edx+2]
upper al
cmp al,"D"
jne find_shade
mov al,[edx+3]
upper al
cmp al,"E"
jne find_shade
clc
ret
fsnoshade:
stc
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Replace 13,10 with 0,0
; In: EDX => start location
; ECX = length
; Out: ?
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
replace:
inc ecx
push ecx
mov al,10
mov edi,edx
re10:
repnz scasb
cmp ecx,0
je re13
mov byte ptr [edi-1],0
jmp re10
re13:
mov al,13
mov edi,edx
pop ecx
re13s:
repnz scasb
cmp ecx,0
je _ret
mov byte ptr [edi-1],0
jmp re13s
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Auto calculate normal
; In:
; EBX = point 1
; ECX = point 2
; EBP = point 3
; Out:
; EBX = finx = x of surface normal of triangle
; ECX = finy = y of surface normal of triangle
; EBP = finz = z of surface normal of triangle
; EAX = D of equation (Ax+By+Cz=D)
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
acalc_normal:
mov esi,connmem
mov eax,[esi+ebx*4+ox]
mov edx,[esi+ebx*4+oy]
mov edi,[esi+ebx*4+oz]
mov lx1,eax
mov ly1,edx
mov lz1,edi
mov eax,[esi+ecx*4+ox]
mov edx,[esi+ecx*4+oy]
mov edi,[esi+ecx*4+oz]
mov lx2,eax
mov ly2,edx
mov lz2,edi
mov eax,[esi+ebp*4+ox]
mov edx,[esi+ebp*4+oy]
mov edi,[esi+ebp*4+oz]
mov lx3,eax
mov ly3,edx
mov lz3,edi
call calc_normal
call calc_d
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
;
; Calc_normal: calculate surface normal
;
; In:
; LX1 - x of point 1 on triangle
; LY1 - y of point 1 on triangle
; LZ1 - z of point 1 on triangle
; LX2 - x of point 2 on triangle
; LY2 - y of point 2 on triangle
; LZ2 - z of point 2 on triangle
; LX3 - x of point 3 on triangle
; LY3 - y of point 3 on triangle
; LZ3 - z of point 3 on triangle
;
; Out:
; EBX = finx = x of surface normal of triangle
; ECX = finy = y of surface normal of triangle
; EBP = finz = z of surface normal of triangle
;
; Notes:
; x2 = x2 - x1
; y2 = y2 - y1
; z2 = z2 - z1
;
; x3 = x3 - x1
; y3 = y3 - y1
; z3 = z3 - z1
;
; x = y2 * z3 - z2 * y3
; y = z2 * x3 - x2 * z3
; z = x2 * y3 - y2 * x3
;
; a = SQR(x ^ 2 + y ^ 2 + z ^ 2)
;
; x = INT(x / a * 256 + .5)
; y = INT(y / a * 256 + .5)
; z = INT(z / a * 256 + .5)
;
; This worked for me on the first try!
;
; If you wanted to get the equation of a plane, you could do this after:
; d = - x * x1 - y * y1 - z * z1
;
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
lx1 dd 0
ly1 dd 0
lz1 dd 0
lx2 dd 0
ly2 dd 0
lz2 dd 0
lx3 dd 0
ly3 dd 0
lz3 dd 0
finx dd 0
finy dd 0
finz dd 0
calc_normal:
mov ebx,lx1
mov ecx,ly1
mov ebp,lz1
sub lx2,ebx
sub ly2,ecx
sub lz2,ebp
sub lx3,ebx
sub ly3,ecx
sub lz3,ebp
mov eax,ly2
mov ebx,lz3
imul ebx
mov ecx,eax
mov eax,lz2
mov ebx,ly3
imul ebx
sub ecx,eax
mov finx,ecx ; save x of normal
mov eax,lz2
mov ebx,lx3
imul ebx
mov ecx,eax
mov eax,lx2
mov ebx,lz3
imul ebx
sub ecx,eax
mov finy,ecx ; save y of normal
mov eax,lx2
mov ebx,ly3
imul ebx
mov ecx,eax
mov eax,ly2
mov ebx,lx3
imul ebx
sub ecx,eax
mov finz,ecx ; save z of normal
calc_testloop:
cmp finx,32768 ; make sure (normal^2)*2 is < 2^32
jge calc_shrit
cmp finy,32768
jge calc_shrit
cmp finz,32768
jge calc_shrit
cmp finx,-32768
jle calc_shrit
cmp finy,-32768
jle calc_shrit
cmp finz,-32768
jg ok_2_bite_dust
calc_shrit:
shr finx,1 ; calculations will be too large if squared, div by 2
test finx,40000000h
jz no_neg_calc1
or finx,80000000h
no_neg_calc1:
shr finy,1
test finy,40000000h
jz no_neg_calc2
or finy,80000000h
no_neg_calc2:
shr finz,1
test finz,40000000h
jz no_neg_calc3
or finz,80000000h
no_neg_calc3:
jmp calc_testloop
ok_2_bite_dust:
mov eax,finx ; x^2
mov edi,eax ; objects
imul edi
mov edi,eax
mov eax,finy ; y^2
mov esi,eax
imul esi
mov esi,eax
mov eax,finz ; z^2
mov ebp,eax
imul ebp
add eax,esi
add eax,edi
call sqrt ; get square root of number
mov ecx,eax
cmp ecx,0
je lam_abort ; should never happen!
mov eax,finx
cdq
shld edx,eax,10
shl eax,10 ; set unit vector to 2^12
idiv ecx
mov finx,eax
mov eax,finy
cdq
shld edx,eax,10
shl eax,10
idiv ecx
mov finy,eax
mov eax,finz
cdq
shld edx,eax,10
shl eax,10
idiv ecx
mov finz,eax
mov ebx,finx
mov ecx,finy
mov ebp,finz
lam_abort:
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Calc_D: Calculate D portion of equation of a plane
; In:
; EBX = x of surface normal of triangle
; ECX = y of surface normal of triangle
; EBP = z of surface normal of triangle
; LX1 - x of point on triangle (any point)
; LY1 - y of point on triangle
; LZ1 - z of point on triangle
; Out:
; EAX = D of equation (Ax+By+Cz=D)
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
calc_d:
mov eax,lx1
imul ebx
mov esi,eax
mov eax,ly1
imul ecx
add esi,eax
mov eax,lz1
imul ebp
add eax,esi
shr eax,10 ; reduce result to avoid inaccuracy
test eax,00200000h
jz calc_o
or eax,0ffc00000h
calc_o:
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
;
; Sqrt: Routine courtesy TRAN
;
; In:
; EAX - number to take root of
; Out:
; EAX - root
;
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
sqrtbasetbl db 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225
sqrt:
pushad
mov ebp,eax
bsr ebx,eax
jnz short sqrtf0
xor ebx,ebx
sqrtf0:
shr ebx,3
lea eax,[ebx*8]
mov cl,32
sub cl,al
rol ebp,cl
mov eax,ebp
movzx eax,al
mov edi,offset sqrtbasetbl
mov ecx,10h
sqrtl0:
scasb
je short sqrtl0d
jb short sqrtl0d2
loop sqrtl0
inc edi
sqrtl0d2:
dec edi
inc cl
sqrtl0d:
movzx edx,byte ptr [edi-1]
dec cl
xor cl,0fh
mov edi,ecx
mov ecx,ebx
jecxz short sqrtdone
sub eax,edx
sqrtml:
shld eax,ebp,8
rol ebp,8
mov ebx,edi
shl ebx,5
xor edx,edx
mov esi,eax
div ebx
rol edi,4
add edi,eax
add ebx,eax
sqrtf2:
imul eax,ebx
mov edx,eax
mov eax,esi
sub eax,edx
jc short sqrtf1
loop sqrtml
sqrtdone:
mov [esp+28],edi
popad
ret
sqrtf1:
dec ebx
dec edi
movzx eax,bl
and al,1fh
jmp sqrtf2
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search and Build points table
; In:
; EBX - x of point
; ECX - y of point
; EBP - z of point
; Out:
; EAX - assigned point number
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
check_point:
mov eax,ebx
or eax,ecx
or eax,ebp
jnz cpnotnull
ret
cpnotnull:
mov esi,connmem
mov eax,1
cploop:
cmp dword ptr [esi+eax*4+ox],0
jne ckdotest
cmp dword ptr [esi+eax*4+oy],0
jne ckdotest
cmp dword ptr [esi+eax*4+oz],0
jne ckdotest
mov [esi+eax*4+ox],ebx
mov [esi+eax*4+oy],ecx
mov [esi+eax*4+oz],ebp
inc points
cmp eax,maxpoints
jae exiterr4
ret
ckdotest:
cmp [esi+eax*4+ox],ebx
jne cknotest
cmp [esi+eax*4+oy],ecx
jne cknotest
cmp [esi+eax*4+oz],ebp
jne cknotest
ret
cknotest:
inc eax
cmp eax,maxpoints
jae exiterr4
jmp cploop
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Get next number (float) after string EDX
; In: EDX => string to search for
; Out:EAX = 32bit float number (fake float, you know what I mean)
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
getnumber:
mov edi,fileloc
mov ebp,dxfo
add ebp,dxfsize
call search_string
jc gn_nf
mov edx,edi
call next
mov fileloc,edx
call _get_float32
push eax
mov edx,fileloc
call next
mov fileloc,edx
pop eax
clc
gn_nf:
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Add DXF into connections, points, calculate normals and load materials.
;
; This adds a DXF file to the already loaded connections (usually empty), but
; you could mix more than one DXF file if you really wanted to.
;
; Psuedo code:
;
;Variables p= x(p) y(p) z(p)
; c= sd(c) p1(c) p2(c) wg(c) wc(c) a(c) b(c) c(c) d(c) mt(c)
; c = connections
; p = points
; sd = surface number
; p1 = point 1 (start of line)
; p2 = point 2 (end of line)
; wg = where are we going
; wc = where did we come from
; a,b,c,d = equation of plane
; mt = material texture for surface (layer name)
;
;search "3DFACE" not found => exit
; search "8"
; call next
; assign material
;
;search "10" => x(p)
;search "20" => y(p)
;search "30" => z(p)
;search "11" => x(p+1)
;search "21" => y(p+1)
;search "31" => z(p+1)
;search "12" => x(p+2)
;search "22" => y(p+2)
;search "32" => z(p+2)
;search "13" => x(p+3)
;search "23" => y(p+3)
;search "33" => z(p+3)
;
; m(c+0) = material
; p1(c+0) =(p+0)
; p2(c+0) =(p+1)
; wg(c+0) =(c+1)
; wc(c+0) =(c+3)
; m(c+1) = material
; p1(c+1) =(p+0)
; p2(c+1) =(p+1)
; wg(c+1) =(c+2)
; wc(c+1) =(c+0)
; m(c+2) = material
; p1(c+2) =(p+0)
; p2(c+2) =(p+1)
; wg(c+2) =(c+3)
; wc(c+2) =(c+1)
; m(c+3) = material
; p1(c+3) =(p+0)
; p2(c+3) =(p+1)
; wg(c+3) =(c+0)
; wc(c+3) =(c+2)
;
; calc normal
; calc D
; d(c+0)=D
; d(c+1)=D
; d(c+2)=D
; d(c+3)=D
;
; if 10=40
; if 11=41
; if 12=42
; wg(c+2)=c+0
; wc(c+0)=c+2
; c=c-1
; p=p-1
; p=p+4
; c=c+4
; goto search face
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
tag1 db "3DFACE",0
tag2 db "8",0
tagx db "10",0,0
db "11",0,0
db "12",0,0
db "13",0,0
tagy db "20",0,0
db "21",0,0
db "22",0,0
db "23",0,0
tagz db "30",0,0
db "31",0,0
db "32",0,0
db "33",0,0
dxf_3dfaces:
mov edx,offset tag1
mov edi,fileloc
mov ebp,dxfo
add ebp,dxfsize
call search_string
jc _ret
mov edx,offset tag2
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc dxf_3dfaces ; no layer to surface?
mov edx,edi
call next
mov fileloc,edx
call assign_material
mov thismaterial,eax
cmp layer,no
je dxf_nosel
mov ecx,eax
call find_info
cmp edx,offset fidefault
je dxf_3dfaces
dxf_nosel:
mov temp1,0
dxf_lp1:
mov ecx,temp1
lea edx,[tagx+ecx*4]
call getnumber
add eax,nx
mov ebx,scale
imul32 ebx
add eax,nu
push eax
mov ecx,temp1
lea edx,[tagy+ecx*4]
call getnumber
add eax,ny
mov ebx,scale
imul32 ebx
add eax,nw
push eax
mov ecx,temp1
lea edx,[tagz+ecx*4]
call getnumber
add eax,nz
mov ebx,scale
imul32 ebx
add eax,nv
cmp yneg,yes
je noyneg
neg eax
noyneg:
mov ecx,eax
pop ebp
pop ebx
call check_point
push eax
inc temp1
cmp temp1,4
jne dxf_lp1
pop edx ; 3
pop ecx ; 2
pop ebx ; 1
pop eax ; 0
mov ebp,connections
mov esi,connmem
mov edi,surfaces
cmp eax,ecx ; check for point: 1,1,1,1
je dxf_point
cmp eax,ecx ; check for line: 1,2,1,2 or 1,2,1,1
je dxf_line
cmp eax,edx ; check for triangle: 0 1 2 0 or 0 1 2 2
je dxf_tri
cmp ecx,edx
jne dxf_4point ; must be a 4 point surface...
dxf_tri:
mov [esi+(ebp+0)*4+p1],eax ; p1(ebp)=eax
mov [esi+(ebp+0)*4+p2],ebx ; p2(ebp)=ebx
mov [esi+(ebp+1)*4+p1],ebx ; p1(ebp+1)=ebx
mov [esi+(ebp+1)*4+p2],ecx ; p2(ebp+1)=ecx
mov [esi+(ebp+2)*4+p1],ecx ; p1(ebp+2)=ecx
mov [esi+(ebp+2)*4+p2],eax ; p2(ebp+2)=eax
mov [esi+(ebp+0)*4+wc],ebp ; wc(ebp)=ebp+2
mov [esi+(ebp+1)*4+wc],ebp ; wc(ebp+1)=ebp+0
mov [esi+(ebp+2)*4+wc],ebp ; wc(ebp+2)=ebp+1
add dword ptr [esi+(ebp+0)*4+wc],2
add dword ptr [esi+(ebp+2)*4+wc],1
mov [esi+(ebp+0)*4+wg],ebp ; wg(ebp)=ebp+1
mov [esi+(ebp+1)*4+wg],ebp ; wg(ebp+1)=ebp+2
mov [esi+(ebp+2)*4+wg],ebp ; wg(ebp+2)=ebp+0
add dword ptr [esi+(ebp+0)*4+wg],1
add dword ptr [esi+(ebp+1)*4+wg],2
mov [esi+(ebp+0)*4+sd],edi ; sd(ebp)=surface number
mov [esi+(ebp+1)*4+sd],edi
mov [esi+(ebp+2)*4+sd],edi
mov edi,thismaterial
mov [esi+(ebp+0)*4+mt],edi ; set material for surface
mov [esi+(ebp+1)*4+mt],edi
mov [esi+(ebp+2)*4+mt],edi
mov ebp,ecx
mov ecx,ebx
mov ebx,eax
call acalc_normal
mov edi,connections
mov esi,connmem
mov [esi+(edi+0)*4+ea],ebx
mov [esi+(edi+0)*4+eb],ecx
mov [esi+(edi+0)*4+ec],ebp
mov [esi+(edi+0)*4+ed],edx
mov [esi+(edi+1)*4+ea],ebx
mov [esi+(edi+1)*4+eb],ecx
mov [esi+(edi+1)*4+ec],ebp
mov [esi+(edi+1)*4+ed],edx
mov [esi+(edi+2)*4+ea],ebx
mov [esi+(edi+2)*4+eb],ecx
mov [esi+(edi+2)*4+ec],ebp
mov [esi+(edi+2)*4+ed],edx
add surfaces,1
add connections,3
jmp dxf_3dfaces
dxf_4point:
mov [esi+(ebp+0)*4+p1],eax ; p1(ebp)=eax
mov [esi+(ebp+0)*4+p2],ebx ; p2(ebp)=ebx
mov [esi+(ebp+1)*4+p1],ebx ; p1(ebp+1)=ebx
mov [esi+(ebp+1)*4+p2],ecx ; p2(ebp+1)=ecx
mov [esi+(ebp+2)*4+p1],ecx ; p1(ebp+2)=ecx
mov [esi+(ebp+2)*4+p2],edx ; p2(ebp+2)=edx
mov [esi+(ebp+3)*4+p1],edx ; p1(ebp+3)=edx
mov [esi+(ebp+3)*4+p2],eax ; p2(ebp+3)=eax
mov [esi+(ebp+0)*4+wc],ebp ; wc(ebp)=ebp+3
mov [esi+(ebp+1)*4+wc],ebp ; wc(ebp+1)=ebp+0
mov [esi+(ebp+2)*4+wc],ebp ; wc(ebp+2)=ebp+1
mov [esi+(ebp+3)*4+wc],ebp ; wc(ebp+3)=ebp+2
add dword ptr [esi+(ebp+0)*4+wc],3
add dword ptr [esi+(ebp+2)*4+wc],1
add dword ptr [esi+(ebp+3)*4+wc],2
mov [esi+(ebp+0)*4+wg],ebp ; wg(ebp)=ebp+1
mov [esi+(ebp+1)*4+wg],ebp ; wg(ebp+1)=ebp+2
mov [esi+(ebp+2)*4+wg],ebp ; wg(ebp+2)=ebp+3
mov [esi+(ebp+3)*4+wg],ebp ; wg(ebp+3)=ebp+0
add dword ptr [esi+(ebp+0)*4+wg],1
add dword ptr [esi+(ebp+1)*4+wg],2
add dword ptr [esi+(ebp+2)*4+wg],3
mov [esi+(ebp+0)*4+sd],edi ; sd(ebp)=surface number
mov [esi+(ebp+1)*4+sd],edi
mov [esi+(ebp+2)*4+sd],edi
mov [esi+(ebp+3)*4+sd],edi
mov edi,thismaterial
mov [esi+(ebp+0)*4+mt],edi ; set material for surface
mov [esi+(ebp+1)*4+mt],edi
mov [esi+(ebp+2)*4+mt],edi
mov [esi+(ebp+3)*4+mt],edi
mov ebp,ecx
mov ecx,ebx
mov ebx,eax
call acalc_normal
mov edi,connections
mov esi,connmem
mov [esi+(edi+0)*4+ea],ebx
mov [esi+(edi+0)*4+eb],ecx
mov [esi+(edi+0)*4+ec],ebp
mov [esi+(edi+0)*4+ed],edx
mov [esi+(edi+1)*4+ea],ebx
mov [esi+(edi+1)*4+eb],ecx
mov [esi+(edi+1)*4+ec],ebp
mov [esi+(edi+1)*4+ed],edx
mov [esi+(edi+2)*4+ea],ebx
mov [esi+(edi+2)*4+eb],ecx
mov [esi+(edi+2)*4+ec],ebp
mov [esi+(edi+2)*4+ed],edx
mov [esi+(edi+3)*4+ea],ebx
mov [esi+(edi+3)*4+eb],ecx
mov [esi+(edi+3)*4+ec],ebp
mov [esi+(edi+3)*4+ed],edx
add surfaces,1
add connections,4
jmp dxf_3dfaces
dxf_line:
mov [esi+(ebp+0)*4+p1],eax ; p1(ebp)=eax
mov [esi+(ebp+0)*4+p2],ebx ; p2(ebp)=ebx
mov [esi+(ebp+1)*4+p1],ebx ; p1(ebp+1)=ebx
mov [esi+(ebp+1)*4+p2],eax ; p2(ebp+1)=ecx
mov [esi+(ebp+0)*4+wc],ebp ; wc(ebp)=ebp+1
mov [esi+(ebp+1)*4+wc],ebp ; wc(ebp+1)=ebp+0
add dword ptr [esi+(ebp+0)*4+wc],1
mov [esi+(ebp+0)*4+wg],ebp ; wg(ebp)=ebp+1
mov [esi+(ebp+1)*4+wg],ebp ; wg(ebp+1)=ebp+0
add dword ptr [esi+(ebp+0)*4+wg],1
mov [esi+(ebp+0)*4+sd],edi ; sd(ebp)=surface number
mov [esi+(ebp+1)*4+sd],edi
mov edi,thismaterial
mov [esi+(ebp+0)*4+mt],edi ; set material for surface
mov [esi+(ebp+1)*4+mt],edi
xor eax,eax
mov edi,connections
mov esi,connmem
mov [esi+(edi+0)*4+ea],eax
mov [esi+(edi+0)*4+eb],eax
mov [esi+(edi+0)*4+ec],eax
mov [esi+(edi+0)*4+ed],eax
mov [esi+(edi+1)*4+ea],eax
mov [esi+(edi+1)*4+eb],eax
mov [esi+(edi+1)*4+ec],eax
mov [esi+(edi+1)*4+ed],eax
add surfaces,1
add connections,2
jmp dxf_3dfaces
dxf_point:
mov [esi+(ebp+0)*4+p1],eax ; p1(ebp)=eax
mov [esi+(ebp+0)*4+p2],eax ; p2(ebp)=ebx
mov [esi+(ebp+0)*4+wc],ebp ; wc(ebp)=ebp+0
mov [esi+(ebp+0)*4+wc],ebp ; wc(ebp+1)=ebp+0
mov [esi+(ebp+0)*4+wg],ebp ; wg(ebp)=ebp+0
mov [esi+(ebp+1)*4+wg],ebp ; wg(ebp+1)=ebp+0
mov [esi+(ebp+0)*4+sd],edi ; sd(ebp)=surface number
mov edi,thismaterial
mov [esi+(ebp+0)*4+mt],edi ; set material for surface
xor eax,eax
mov edi,connections
mov esi,connmem
mov [esi+(edi+0)*4+ea],eax
mov [esi+(edi+0)*4+eb],eax
mov [esi+(edi+0)*4+ec],eax
mov [esi+(edi+0)*4+ed],eax
add surfaces,1
add connections,1
jmp dxf_3dfaces
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Input Polyline PFACEs
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
tag3 db "POLYLINE",0
tag4 db "VERTEX",0
tag70 db "70",0
tag71 db "71",0
tag72 db "72",0
tag73 db "73",0
tag74 db "74",0
dxf_polylines:
mov edx,offset tag3
mov edi,fileloc
mov ebp,dxfo
add ebp,dxfsize
call search_string
jc _ret
mov edx,offset tag2
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc dxf_polylines ; no layer to polyline?
mov edx,edi
call next
mov fileloc,edx
call assign_material
mov thismaterial,eax
cmp layer,no
je dxf_pnosel
mov ecx,eax
call find_info
cmp edx,offset fidefault
je dxf_polylines
dxf_pnosel:
mov edx,fileloc
call next
mov edi,edx
mov edx,offset tag70
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov edx,edi
call next
call _strhtn
call _vct16
cmp eax,64
jne dxf_polylines
mov edx,fileloc
call next
mov edi,edx
mov edx,offset tag71
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov edx,edi
call next
call _strhtn
call _vct32
mov pvertexs,eax
mov edx,fileloc
call next
mov edi,edx
mov edx,offset tag72
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov edx,edi
call next
mov fileloc,edx
call _strhtn
call _vct32
mov pfaces,eax
mov temp2,eax
mov temp1,1
dxfpv_load:
mov edi,fileloc
mov edx,offset tag4
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov fileloc,edi
mov edx,offset tagx
call getnumber
add eax,nx
mov ebx,scale
imul32 ebx
add eax,nu
push eax
mov edx,offset tagy
call getnumber
add eax,ny
mov ebx,scale
imul32 ebx
add eax,nw
push eax
mov edx,offset tagz
call getnumber
add eax,nz
mov ebx,scale
imul32 ebx
add eax,nv
cmp yneg,yes
je noynegp
neg eax
noynegp:
mov ecx,eax
pop ebp
pop ebx
call check_point
mov edi,temp1
mov polyindex[edi*4],eax
inc temp1
mov eax,temp1
cmp eax,pvertexs
jbe dxfpv_load
dxf_pmore:
mov edi,fileloc ; now reconstruct polyline into face
mov edx,offset tag4
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov edx,offset tag71
call getnumber
shr eax,16
mov start,eax
mov ebp,connections ; set first point in poly
mov startconn,ebp
mov eax,[polyindex+eax*4]
mov esi,connmem
mov [esi+ebp*4+p1],eax
mov edx,offset tag72
call getnumber
jc exiterr6
shr eax,16
movsx eax,ax
mov temp3,0
cmp eax,0
jge pf_kkl
neg eax
mov temp3,1
pf_kkl:
cmp eax,start
je pf_close
call addpoint
cmp temp3,1
je pf_close
mov edx,offset tag73
call getnumber
jc pf_close
shr eax,16
movsx eax,ax
mov temp3,0
cmp eax,0
jge pf_kkq
neg eax
mov temp3,1
pf_kkq:
cmp eax,start
je pf_close
call addpoint
cmp temp3,1
je pf_close
mov edx,offset tag74
call getnumber
jc pf_close
shr eax,16
movsx eax,ax
mov temp3,0
cmp eax,0
jge pf_negit
neg eax
mov temp3,1
pf_negit:
cmp eax,start
je pf_close
call addpoint
cmp temp3,0
je pf_close
pf_multi:
mov edi,fileloc
mov edx,offset tag4
mov ebp,dxfsize
add ebp,dxfo
call search_string
jc exiterr6
mov edx,offset tag73
call getnumber
jc exiterr6
shr eax,16
movsx eax,ax
mov temp3,0
cmp eax,0
jge pf_negitp
neg eax
mov temp3,1
pf_negitp:
cmp eax,start
je pf_close
call addpoint
cmp temp3,1
je pf_multi
pf_close:
mov eax,startconn
mov ebp,connections
mov esi,connmem
mov [esi+eax*4+wc],ebp
mov [esi+ebp*4+wg],eax
mov ebx,start
mov [esi+ebp*4+p2],ebx
mov eax,thismaterial
mov [esi+ebp*4+mt],eax
mov eax,surfaces
mov [esi+ebp*4+sd],eax
inc connections
inc surfaces
dec pfaces
jnz dxf_pmore
jmp dxf_polylines
addpoint:
mov ebp,connections
mov eax,[polyindex+eax*4]
mov esi,connmem
mov [esi+ebp*4+p2],eax
mov [esi+(ebp+1)*4+p1],eax
mov [esi+ebp*4+wg],ebp
inc dword ptr [esi+ebp*4+wg]
mov eax,surfaces
mov [esi+ebp*4+sd],eax
mov eax,thismaterial
mov [esi+ebp*4+mt],eax
inc connections
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Find opposite connection for line EBP
; In: EBX = connection to find pair for
; Out: CF = 1 not found, CF = 0 connection found at EDI!
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
find_pair:
mov esi,connmem
mov ecx,[esi+ebp*4+p1] ; eg have (7,9) look for (9,7)
mov edx,[esi+ebp*4+p2]
mov eax,ecx
or eax,edx
jz fpnomatch
xor edi,edi
fploop:
mov eax,[esi+edi*4+p2]
mov ebx,[esi+edi*4+p1]
cmp eax,ecx
jne fpnotmatch0
cmp ebx,edx
jne fpnotmatch0 ; backwards points?
mov eax,[esi+ebp*4+ea] ; yes, test if same plane equation
cmp [esi+edi*4+ea],eax
jne fpnotmatch1
mov eax,[esi+ebp*4+eb]
cmp [esi+edi*4+eb],eax
jne fpnotmatch1
mov eax,[esi+ebp*4+ec]
cmp [esi+edi*4+ec],eax
jne fpnotmatch1
mov eax,[esi+ebp*4+ed]
cmp [esi+edi*4+ed],eax
jne fpnotmatch1
mov eax,[esi+ebp*4+mt] ; same equation, test if same material
cmp [esi+edi*4+mt],eax
jne fpnotmatch1
clc
ret
fpnotmatch0:
or eax,ebx
jz fpnomatch
fpnotmatch1:
inc edi
cmp edi,maxpoints
jl fploop
fpnomatch:
mov edi,-1
stc
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Renumber surfaces
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
renumber_surfaces:
xor ebx,ebx
rnloop:
call rn_lowest
jc _ret
call rn_eax2ebx
inc ebx
jmp rnloop
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Search for lowest surface number (but above EBX)
; In: EBX = lowest surface number to test
; Out:
; CF = 1, not found.
; CF = 0
; EAX = lowest surface number
; EBP = connection number where found
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
rn_lowest:
mov esi,connmem
mov ecx,connections
mov eax,-1
rnlloop:
mov edx,[esi+(ecx-1)*4+sd]
cmp ebx,edx
ja rnlnotel
cmp eax,edx
jb rnlnotel
mov eax,edx
mov ebp,ecx
dec ebp
rnlnotel:
loop rnlloop
inc eax
sub eax,1
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Renumber surfaces EAX to EBX
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
rn_eax2ebx:
mov esi,connmem
lea edi,[esi+sd]
mov ecx,connections
rn_eaxl:
repnz scasd
cmp ecx,0
jz _ret
mov [edi-4],ebx
jmp rn_eaxl
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Delete unused points and collect
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
collect_points:
mov esi,connmem
mov eax,1
coploop:
lea edi,[esi+p1]
mov ecx,connections
repnz scasd
sub ecx,1
jnc cpused
lea edi,[esi+p2]
mov ecx,connections
repnz scasd
sub ecx,1
jnc cpused
call cpdeleteit
cpused:
inc eax
cmp eax,points
jne coploop
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Delete point EAX
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
cpdeleteit:
mov ebp,points
mov esi,connmem
lea ecx,[ebp-eax]
lea edi,[esi+(eax+0)*4+ox]
lea esi,[esi+(eax+1)*4+ox]
rep movsd
mov esi,connmem
lea ecx,[ebp-eax]
lea edi,[esi+(eax+0)*4+oy]
lea esi,[esi+(eax+1)*4+oy]
rep movsd
mov esi,connmem
lea ecx,[ebp-eax]
lea edi,[esi+(eax+0)*4+oz]
lea esi,[esi+(eax+1)*4+oz]
rep movsd
mov esi,connmem
mov ecx,connections
xor ebp,ebp
cpdloop:
mov ebx,[esi+ebp*4+p1]
cmp ebx,eax
jb cpskip1
dec dword ptr [esi+ebp*4+p1]
cpskip1:
mov ebx,[esi+ebp*4+p2]
cmp ebx,eax
jb cpskip2
dec dword ptr [esi+ebp*4+p2]
cpskip2:
inc ebp
loop cpdloop
dec points
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Number sides in preparation for sort
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
number_them:
mov esi,connmem
mov ecx,surfaces
dec ecx
tnkl:
mov [esi+(ecx)*4+sn],ecx
loop tnkl
mov [esi+(ecx)*4+sn],ecx
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Wipe D value from plane equation if no iteration used
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
wipe_d:
cmp iterate,yes
je _ret
mov esi,connmem
mov ecx,connections
dec ecx
xor edx,edx
wdkl:
mov [esi+(ecx)*4+ed],edx
loop wdkl
mov [esi+(ecx)*4+ed],edx
ret
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
; Output file - file is opened and ready
;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
output_file:
mov ecx,8 ; output header info
mov al,"."
mov edi,offset outputname
repnz scasb
mov byte ptr [edi-1],0
sub edi,offset outputname
push edi
push edi
mov edx,offset header0
call _write_null
mov edx,offset header1
call _write_null
mov edx,offset outputname
call _write_null
pop ecx
mov edx,offset header7
add edx,ecx
call _write_null
mov edx,offset header2
call _write_null
mov edx,offset outputname
call _write_null
mov edx,offset header3
call _write_null
mov edx,offset outputname
call _write_null
pop ecx
mov edx,offset header4
add edx,ecx
call _write_null
mov eax,points
call _write_dec16
mov eax,","
call _write_string4
mov eax,surfaces
call _write_dec16
call _write_ret
mov edx,offset header4
call _write_null
mov edx,offset header5
call _write_null
call _write_ret
call _write_ret
mov temp1,1 ; now output points
of_loop1:
mov edx,offset header4
call _write_null
mov esi,connmem
mov ecx,temp1
mov eax,[esi+ecx*4+ox]
mov edx,offset buffer
call _write_neg16
call _write_null
mov eax,","
call _write_string4
mov esi,connmem
mov ecx,temp1
mov eax,[esi+ecx*4+oy]
mov edx,offset buffer
call _write_neg16
call _write_null
mov eax,","
call _write_string4
mov esi,connmem
mov ecx,temp1
mov eax,[esi+ecx*4+oz]
mov edx,offset buffer
call _write_neg16
call _write_null
mov edx,offset header6
call _write_null
mov eax,temp1
call _write_dec16
call _write_ret
inc temp1
mov ecx,temp1
cmp ecx,points
jbe of_loop1
call _write_ret
mov temp1,0 ; output surfaces
dp_sloop:
mov ebx,temp1
call rn_lowest
mov temp2,ebp
mov edx,offset header4
call _write_null
mov esi,connmem
mov ecx,temp2
mov ecx,[esi+ecx*4+mt]
call find_info
mov thismaterial,edx
mov edx,thismaterial
call find_shade
jc dp_noshade0
mov esi,connmem
mov ebp,temp2
mov ebp,[esi+ebp*4+wg]
mov ebp,[esi+ebp*4+wg]
cmp ebp,temp2
jne dp_noshade0
mov edx,offset fidefaull
mov thismaterial,edx
dp_noshade0:
mov edx,thismaterial
call _write_null
mov eax,","
call _write_string4
mov ebp,temp2
mov esi,connmem
mov eax,[esi+ebp*4+p1]
call _write_dec16
dp_cloop:
mov temp3,ebp
mov eax,","
call _write_string4
mov esi,connmem
mov ebp,temp3
mov eax,[esi+ebp*4+p2]
call _write_dec16
mov esi,connmem
mov ebp,temp3
mov ebp,[esi+ebp*4+wg]
cmp temp2,ebp
jne dp_cloop
mov edx,thismaterial
call find_shade
jc dp_noshade
mov esi,connmem
mov ebp,temp2
mov ebp,[esi+ebp*4+wg]
mov ebp,[esi+ebp*4+wg]
cmp ebp,temp2
je dp_noshade
cmp tnormal,no
je normalnormal
mov eax,","
call _write_string4
mov esi,connmem
mov ebp,temp2
mov eax,[esi+ebp*4+ea]
shr eax,2
mov edx,offset buffer
call _write_neg16
call unpad
call _write_null
mov eax,","
call _write_string4
mov esi,connmem
mov ebp,temp2
mov eax,[esi+ebp*4+eb]
shr eax,2
mov edx,offset buffer
call _write_neg16
call unpad
call _write_null
mov eax,","
call _write_string4
mov esi,connmem
mov ebp,temp2
mov eax,[esi+ebp*4+ec]
shr eax,2
mov edx,offset buffer
call _write_neg16
call unpad
call _write_null
jmp dp_noshade
normalnormal:
mov edx,offset header9
call _write_null
dp_noshade:
call _write_ret
inc temp1
mov ecx,temp1
cmp ecx,surfaces
jne dp_sloop
call _write_ret
ret
header0 db ";DXF23DV converter V0.1 - This conversion conforms to version 3DVECT35",13,10,13,10,0
header1 db "h",0
header2 db "-1",13,10," dd offset o",0
header3 db " - offset $ - 4",13,10,13,10,"o",0
header4 db " dw ",0
header5 db "25 dup (0)",0
header6 db " ; point ",0
header7 db " dd ",0
header8 db " offset o",0
header9 db ",0,0,0",0
code32 ends
end