⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmaterials.cls

📁 3ds文件浏览程序
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CMaterials"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Collection" ,"CMaterial"
Attribute VB_Ext_KEY = "Member0" ,"CMaterial"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
'*************************************************************************
'FUNCTION: collection of materials.
'AUTHOR: VB wizard
'HISTORY: -
'NOTES: If a mesh may use the same material in several places, this class
'can prevent duplication. But its main purpose is to support the material
'browser.
'*************************************************************************
Private mCol As Collection
Public DefaultMat As CMaterial

Private Sub Class_Initialize()
    Set mCol = New Collection
    Set DefaultMat = New CMaterial
End Sub

Private Sub Class_Terminate()
    Set mCol = Nothing
End Sub

Public Function Add(ParentNode As CNode, Name As String, material As CMaterial) As Long
Dim matIndex&
On Error GoTo ErrorHandler
    matIndex = GetIndex(Name)
    If Not matIndex = 0 Then
        Debug.Assert 0
        Add = matIndex
    Else
        material.Name = Name
        mCol.Add material, Name
        Add = mCol.Count
    End If
    '
    'add a reference to the material in the node so that
    'the material will be drawn in the tree
    If Not ParentNode Is Nothing Then
        ParentNode.AddFieldObj material
    End If
    Set material.Parent = ParentNode
    '
    If mCol.Count = 1 Then
        material.TurnWhite
    End If
'----------------------------------------------------
Exit Function
ErrorHandler:
    Debug.Assert 0
    Debug.Print Err.Description
    Exit Function
    Resume Next
End Function

Public Property Get Item(Name$) As CMaterial
Attribute Item.VB_UserMemId = 0
    Set Item = mCol(Name)
End Property

Public Property Get ItemFromIndex(Index&) As CMaterial
    Set ItemFromIndex = mCol(Index)
End Property

Public Property Get Count() As Long
    Count = mCol.Count
End Property

Public Sub Remove(Index&)
    mCol.Remove Index
End Sub

Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
    Set NewEnum = mCol.[_NewEnum]
End Property

Public Sub Clear()
Dim i&
    For i = 1 To mCol.Count
        mCol.Remove 1
    Next
End Sub

Public Function GetIndex&(Name$)
Dim i&
    For i = 1 To mCol.Count
        If StrComp(Name, mCol(i).Name, 1) = 0 Then
            GetIndex = i
            Exit Function
        End If
    Next
    'return 0 and the caller will get 'defaultmat'
End Function

Public Sub LoadMaps(Path$)
Dim i&
    For i = 1 To mCol.Count
        mCol(i).LoadMaps Path
    Next
    'return 0 and the caller will get 'defaultmat'
End Sub

Public Function SetMaterial(Index&) As CMaterial
Dim m As CMaterial
    If Index > 0 And Index <= mCol.Count Then
        Set m = mCol(Index)
        m.SetMaterial
        Set SetMaterial = m
    ElseIf Index = 0 Then
        DefaultMat.SetMaterial
        Set SetMaterial = DefaultMat
    Else
        Debug.Assert 0
    End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -