DiGraph - Verge3D 用户手册 - Soft8Soft
Description: 了解如何在使用 Verge3D 制作的交互式 3D 应用程序中使用 DiGraph

# DiGraph

A directed acyclic graph (DAG). In Verge3D this structure is used to define the hierarchy of node-based materials.

## Constructor

### DiGraph(V : Integer)

Create a new graph of the size (number of nodes) `V`.

## Properties

### # .V : Integer

Graph size.

### # .adjList : Array

Graph adjacency list.

### # .nodeInfo : Array

Data attached to graph nodes.

### # .edges : Object

Graph edges.

## Methods

### # .addNode(nodeInfo : Object)

Add a new node to the graph and attach .nodeInfo data to it.

### # .removeAll()

Remove all nodes and edges from the graph.

### # .addEdge(edge : Edge)

Add an edge to the graph.

### # .addNewEdge(v : Integer, w : Integer) → Edge

Add a new edge to the graph which connects nodes `v` and `w`.

### # .removeEdge(v : Integer, w : Integer)

Remove an edge from the graph which connects nodes `v` and `w`.

### # .edge(v : Integer, w : Integer) → Edge

Return an edge which connects nodes `v` and `w`. Return `null` if no such edge is found.

### # .adj(v : Integer) → Integer

Return node adjacent to node `v`.

### # .node(v : Integer) → Object

Return node info data for node `v`.

### # .nodeINdex(nodeInfo : Object) → Integer

Return the index of the node which has the passed .nodeInfo data.

### # .reverse() → DiGraph

Return a new graph which has all edges reversed. The source graph remains intact.

### # .len() → DiGraph

Return graph size.

### # .findInEdges(v : Integer) → Array

Return input edges for node `v`.

### # .findOutEdges(v : Integer) → Array

Return output edges for node `v`.

### # .disconnect(v : Integer, removeNode : Boolean)

Disconnect node `v` from the graph. If `removeNode=false` (default) leave the disconnected node inside the graph. If `removeNode=true` remove the node (with its data) as well.

### # .insert(G : DiGraph, edgesInG : Array, edgesOutG : Array, copyNodeCb : Function, copyEdgeCb : Function)

Insert a `G` subgraph into the graph. The `edgesInG` and `edgesOutG` arrays represent input and output edges which will be used to connect the subgraph. Optional callbacks `copyNodeCb` and `copyEdgeCb` are executed per node/edge inserted to the graph.

### # .vis(labelCallback : Function)

Convert the graph to the DOT (Graphviz) format and print to the browser console. Optional `labelCallback` is used to assign labels for the printed graph nodes. It accepts node index and node info as parameters.

## 源代码

关于如何获取此模块的源代码，请查看 本页。