Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
TRAX
aquarium 1.1
Text Box Xtra
Set Frame Rate for Flash Member
Line Skip-Alphamania
Prepare for movie (Sound Card and Screen Saver Check)
Writing HTML in Text member
MUSTARD
simZip Xtra
Read a File
 

 

 

Behavior 3D Model

Added on 1/31/2000

 

Compatibilities:
D7 D8 Mac PC Script Shockwave

This item has not yet been rated

Author: DaveCole

Allows a 3D model of multiple quads Requires Dave's 3D engine script. The newest version and full example files are always available at http://www.dubbus.com/devnull

-- 3DModel v7.1 Copyright 1998 Dave Cole
--
-- This object represents a general model made up of several 3DQuad
-- objects represented by Quads.  Use this object and any of the
-- proprietary model datafile formats to instantiate a 3D model
-- in director.

-- Model Formats supported so far:
--
-- 0: No format to be directly imported, placeholder object instantiated
-- 1: Field based "D3D" (Dave's 3D) Model (see docs on format)
-- 2: File based "D3D" (Dave's 3D) Model (see docs on format)
-- 3: Field based "P3D" (Point-based Dave's 3D) Model (see docs)
-- 4: File based "P3D" Model
-- 5: .OBJ format pre-imported into a field (Alias Wavefront, etc.)
-- 6: .OBJ files

global mModelView, sortSprites

property mFormat, mDescriptor, mBeginSprite
property mMatrix, mObjectList, curSprite, maxSprite, mArgs, highestUsedSpriteChannel


-- modelformat = Which model format to import, modeldescriptor = the file/field name of the model to import,
-- beginningSpriteChannel = which sprite channel to begin allocating sprites for the model at (counts up)
on new me, modelformat, modeldescriptor, beginningSpriteChannel, highestSpriteChannel, argList
  
  set mFormat = modelformat
  set mDescriptor = modeldescriptor
  set mBeginSprite = beginningSpriteChannel
  set curSprite = mBeginSprite
  set maxSprite = highestSpriteChannel
  highestUsedSpriteChannel = mBeginSprite
  set mMatrix = [[1000, 0, 0, 0], [0, 1000, 0, 0], [0, 0, 1000, 0], [0, 0, 0, 1000]]
  set mObjectList = []
  
  case mFormat of
    0: -- create empty shell of a 3DModel object
      
    1: -- D3D Field
      importD3D(me, mDescriptor)
      
    2: -- D3D File
      set zz = importText(me, mDescriptor, "f_"&mDescriptor)
      importD3D(me, zz)
      
    3: -- P3D Field
      importP3D(me, mDescriptor)
      
    4: -- P3D File
      set zz = importText(me, mDescriptor, "f_"&mDescriptor)
      importP3D(me, zz)
      
    5: -- .OBJ Field
      importOBJ(me, mDescriptor, getAt(arglist, 1), getAt(arglist, 2), getAt(arglist, 3))
      
    6: -- .OBJ File
      set zz = importText(me, mDescriptor, "f_"&mDescriptor, getAt(arglist, 1), getAt(arglist, 2), getAt(arglist, 3))
      importOBJ(me, zz)
      
  end case
  
  return me
end

on kill me
  --  repeat with i = mBeginSprite to highestUsedSpriteChannel
  --    puppetsprite(i, false)
  --  end repeat
  --  updateStage
  --  repeat with i = mBeginSprite to highestUsedSpriteChannel
  --    puppetsprite(i, true)
  --    sprite(i).visible = 1  
  --  end repeat
  put "3dmodel kill"
  z = count(mObjectList)
  repeat with i = 1 to z
    kill(mObjectList[i])
  end repeat
end

on setMouseWithin me, scriptName
  repeat with n in mObjectList
    n.scriptEvents = 1
    n.mySprite.scriptInstanceList.deleteOne(n)
    n.mYSprite.scriptInstanceList.add(n)
    n.mouseWithinS = scriptName
  end repeat
end

on setMouseDown me, scriptName
  repeat with n in mObjectList
    n.scriptEvents = 1
    n.mySprite.scriptInstanceList.deleteOne(n)
    n.mYSprite.scriptInstanceList.add(n)
    n.mouseDownS = scriptName
  end repeat
end

on setMouseUp me, scriptName
   repeat with n in mObjectList
    n.scriptEvents = 1
    n.mySprite.scriptInstanceList.deleteOne(n)
    n.mYSprite.scriptInstanceList.add(n)
    n.mouseUpS = scriptName
  end repeat
end

on setMouseLeave me, scriptName
   repeat with n in mObjectList
    n.scriptEvents = 1
    n.mySprite.scriptInstanceList.deleteOne(n)
    n.mYSprite.scriptInstanceList.add(n)
    n.mouseLeaveS = scriptName
  end repeat
end


on importD3D me, mDescriptor
  set z = the number of lines in field mDescriptor
  set l = 0
  set t = []
  set curSprite = curSprite - 1
  repeat with i = 1 to z
    set m = line i of field mDescriptor
    if char 1 to 2 of m = "--" then
      nothing
    else if word 1 of m = "NEWFACE" then
      set mInk = value(word 2 of m)
      set mBlend = value(word 3 of m)
      set mDCue = value(word 4 of m)
      set mMember = word 5 of m
      set l = 0
      set t = []
      set curSprite = curSprite + 1
      if curSprite > maxSprite then
        exit repeat
      end if
    else if the number of items in m = 3 then
      set l = l + 1
      if l = 4 then
        
        add(t, [value(item 1 of m), value(item 2 of m), value(item 3 of m), 1.0])
        add(mObjectList, new(script "3DQuad", t, curSprite, mInk, mBlend, mDCue, mMember))
        
        
      else if l < 4 then
        add(t, [value(item 1 of m), value(item 2 of m), value(item 3 of m), 1.0])
      end if
      
    end if    
  end repeat
  if curSprite > maxSprite then
    highestUsedSpriteChannel = maxSprite
  else
    highestUsedSpriteChannel = curSprite
  end if
  repeat with i = (highestUsedSpriteChannel) + 1 to maxSprite
    sprite(i).visible = false
  end repeat
end


on importP3D me, mDescriptor
  set z = the number of lines in field mDescriptor
  set l = 0
  set t = []
  set curSprite = curSprite - 1
  repeat with i = 1 to z
    set m = line i of field mDescriptor
    if char 1 to 2 of m = "--" then
      nothing
    else if word 1 of m = "VERTEX" AND the number of words in m >= 10 then    
      set curSprite = curSprite + 1
      if curSprite > maxSprite then
        exit repeat
      end if
      
      --x, y, z, memberName, spriteNumber, theInk, theBlend, dCue_scale, dCue_blend, dCue_memberchange, lowMem, highMem
      if the number of words in m < 12 then
        set lm = 0
        set hm = 0
      else
        set lm = value(word 11 of m)
        set hm = value(word 12 of m)
      end if
      add(mObjectList, new(script "3DSprite", value(word 2 of m), value(word 3 of m), value(word 4 of m), word 5 of m, curSprite, value(word 6 of m), value(word 7 of m), value(word 8 of m), value(word 9 of m), value(word 10 of m), lm, hm))
      
    end if    
  end repeat
  if curSprite > maxSprite then
    highestUsedSpriteChannel = maxSprite
  else
    highestUsedSpriteChannel = curSprite
  end if
end


on importOBJ me, mDescript, mInk, mBlend, mMember
  set vertexList = []
  
  set z = the number of lines in field mDescript
  set curSprite = curSprite - 1
  
  repeat with i = 1 to z
    set m = line i of field mDescript
    if word 1 of m = "v" then
      add(vertexList, [value(word 2 of m), value(word 3 of m), value(word 4 of m), 1.0])
    else if word 1 of m = "f" then
      curSprite = curSprite + 1
      if curSprite <= maxSprite then
        set t = []
        set x = getAt(vertexList, value(word 2 of m))
        add(t, x)
        add(t, getAt(vertexList, value(word 3 of m)))
        add(t, getAt(vertexList, value(word 4 of m)))
        add(t, x)
        add(mObjectList, new(script "3DQuad", t,curSprite, mInk, mBlend, 0, mMember))
      else
        exit repeat
      end if
    end if
    
  end repeat
  if curSprite > maxSprite then
    highestUsedSpriteChannel = maxSprite
  else
    highestUsedSpriteChannel = curSprite
  end if  
  set vertexList = []
end


on importText me, fileN, fieldName
  io = new (xtra "fileio")
  io.openFile(fileN, 1)
  if the number of member fieldName = -1 then
    set n = new(#field)
    set the name of n = fieldName
  end if
  
  put cr2lf(me, readFile(io)) into field fieldName
  return fieldName
end


-- LF (RETURN) = 13, CR (unwanted) = 10
on cr2lf me, str
  if str  contains numtochar(10) then
    set str2 = EMPTY
    repeat with i = 1 to the number of chars in str
      if (char i of str = numtochar(10)) then
        put RETURN after str2
      else
        put char i of str after str2
      end if
    end repeat
  else
    return str
  end if
  return str2
end


-- Save current ModelView matrix into this Model's memory to be recalled
on saveMatrix me
  set mMatrix = mModelView
end

-- Take the ModelView matrix stored in this Model's memory and make it
-- the current ModelView matrix (overwrites the previous ModelView).
on imposeMatrix me
  set mModelView = mMatrix
end

-- Take the ModelView matrix stored in this Model's memory, multiply it
-- against the current ModelView matrix and make that the current ModelView Matrix.
on affectModelViewMatrix me
  set mModelView = Matrix4x4Mult(mMatrix, mModelView)
end

-- Multiply the current ModelView matrix against the locally saved matrix
on affectLocalMatrix me
  set mMatrix = Matrix4x4Mult(mModelView, mMatrix)
end


-- Transform all the vertices in the model
on Transform me
  repeat with n in mObjectList
    Transform(n)
  end repeat
end

-- Draw the model
on drawMe me
  if sortSprites then
    zSort(mObjectList)
  end if
  repeat with n in mObjectList
    drawMe(n)
  end repeat
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail