| 18 | } |
| 19 | |
| 20 | Asset::LoadResult MaterialFunction::load() |
| 21 | { |
| 22 | #if COMPILE_WITH_MATERIAL_GRAPH |
| 23 | // Load graph |
| 24 | const auto surfaceChunk = GetChunk(0); |
| 25 | if (!surfaceChunk || !surfaceChunk->IsLoaded()) |
| 26 | return LoadResult::MissingDataChunk; |
| 27 | MemoryReadStream stream(surfaceChunk->Get(), surfaceChunk->Size()); |
| 28 | if (Graph.Load(&stream, USE_EDITOR)) |
| 29 | return LoadResult::Failed; |
| 30 | |
| 31 | // Cache input and output nodes |
| 32 | bool tooManyInputsOutputs = false; |
| 33 | for (int32 i = 0; i < Graph.Nodes.Count(); i++) |
| 34 | { |
| 35 | auto& node = Graph.Nodes[i]; |
| 36 | if (node.Type == GRAPH_NODE_MAKE_TYPE(16, 1)) |
| 37 | { |
| 38 | if (Inputs.Count() < 16) |
| 39 | Inputs.Add(i); |
| 40 | else |
| 41 | tooManyInputsOutputs = true; |
| 42 | } |
| 43 | else if (node.Type == GRAPH_NODE_MAKE_TYPE(16, 2)) |
| 44 | { |
| 45 | if (Outputs.Count() < 16) |
| 46 | Outputs.Add(i); |
| 47 | else |
| 48 | tooManyInputsOutputs = true; |
| 49 | } |
| 50 | } |
| 51 | if (tooManyInputsOutputs) |
| 52 | { |
| 53 | LOG(Error, "Too many function inputs/outputs in '{0}'. The limit is max 16 inputs and max 16 outputs.", ToString()); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | return LoadResult::Ok; |
| 58 | } |
| 59 | |
| 60 | void MaterialFunction::unload(bool isReloading) |
| 61 | { |