bool Selector::ProcessNaviMesh(Node *node, AI::NaviMesh *mesh) { if (mesh) { auto line = m_local_transform.top().Inversed() * m_view_ray; std::vector<Math::vec3> points; std::vector<size_t> faces; Math::Relation res = Math::CrossLineTriangles(line, mesh->GetPoints(), mesh->GetFaces(), points, faces); if (res == Math::Relation::INTERSECT) { // return points to the worlds coordinate system for (auto& p : points) { p = m_local_transform.top() * p; } Selection selection; selection.SetPoints(points); selection.SetFaces(faces); selection.SetObject(node); m_selections.push_back(selection); } } ProcessChildren(node); return true; }
void FilterNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && !GetChild(0)->IsTerminal() && ChildExists(1) && ChildExists(2)) { float r=GetChild(2)->GetValue(); if (r>=0 && r<0.5) m_Filter.SetResonance(r); if (GetChild(1)->IsTerminal()) { float c=GetChild(1)->GetValue(); if (c>=0 && c<1) m_Filter.SetCutoff(c); m_Filter.Process(bufsize, GetInput(0), m_Output); } else { m_Filter.Process(bufsize, GetInput(0), GetInput(1), m_Output); } } }
bool Selector::ProcessTerrainMesh(Node *node, Virtual::TerrainMesh *terrain) { if (terrain) { Virtual::StaticGeometry* geom = terrain->GetGeometry(); if (geom) { Math::Line3D line = m_local_transform.top().Inversed() * m_view_ray; std::vector<Math::vec3> points; std::vector<size_t> faces; Math::Relation r = Math::CrossLineTriangles(line, geom->GetCpuCache().GetVertices(), geom->GetCpuCache().GetFaces(), points, faces); if (r == Math::Relation::INTERSECT) { Selection selection; // return points to the worlds coordinate system for (auto& p : points) { p = m_local_transform.top() * p; } selection.SetPoints(points); selection.SetFaces(faces); selection.SetObject(node); m_selections.push_back(selection); } } } ProcessChildren(node); return true; }
bool Selector::ProcessTransform(Node *node, Virtual::Transform *value) { if (m_local_transform.empty()) m_local_transform.push(value->Get()); else m_local_transform.push(m_local_transform.top() * value->Get()); bool result = ProcessChildren(node); m_local_transform.pop(); return result; }
void ADSRNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); m_Envelope.Process(bufsize, m_Output); }
void EffectNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && !GetChild(0)->IsTerminal() && ChildExists(1)) { if (m_Type==CLIP) { m_Output=GetInput(0); if (GetChild(1)->IsTerminal()) { HardClip(m_Output, GetChild(1)->GetCVValue()); } else { MovingHardClip(m_Output, GetInput(1)); } } else if (m_Type==DISTORT) { m_Output=GetInput(0); if (GetChild(1)->IsTerminal()) { Distort(m_Output, GetChild(1)->GetCVValue()); } else { MovingDistort(m_Output, GetInput(1)); } } else if (ChildExists(2)) { switch (m_Type) { case CRUSH : m_Output=GetInput(0); Crush(m_Output, GetChild(1)->GetCVValue(), GetChild(2)->GetCVValue()); break; case DELAY : { m_Delay.SetDelay(GetChild(1)->GetCVValue()); m_Delay.SetFeedback(GetChild(2)->GetCVValue()); m_Delay.Process(bufsize, GetInput(0), m_Output); break; } default : assert(0); break; } } } }
void SampleNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); m_Temp.Allocate(bufsize); } ProcessChildren(bufsize); m_Output.Zero(); m_Sampler.Process(bufsize, m_Output, m_Temp); }
void Selector::Process(Node *node) { System::Object* o = node->GetData(); if (o) { auto type = o->GetType(); if (type->IsEqual(&Virtual::StaticGeometry::Info.Type)) ProcessStaticGeometry(node, (Virtual::StaticGeometry*)o); else if (type->IsEqual(&Virtual::SkinGeometry::Info.Type)) ProcessSkinGeometry(node, (Virtual::SkinGeometry*)o); else if (type->IsEqual(&Virtual::Transform::Info.Type)) ProcessTransform(node, (Virtual::Transform*)o); else if (type->IsEqual(&AI::NaviMesh::Info.Type)) ProcessNaviMesh(node, (AI::NaviMesh*)0); else if (type->IsEqual(&Virtual::TerrainMesh::Info.Type)) ProcessTerrainMesh(node, (Virtual::TerrainMesh*)o); else ProcessChildren(node); } else { ProcessChildren(node); } }
void OscNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && !GetChild(0)->IsTerminal()) { m_WaveTable.ProcessFM(bufsize, m_Output, GetInput(0)); } else { m_WaveTable.Process(bufsize, m_Output); } }
void PadNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); bool HaveFreqCV = false; bool HaveGapCV = false; // if frequency cv exists HaveFreqCV=ChildExists(0) && !GetChild(0)->IsTerminal(); HaveGapCV=ChildExists(1) && !GetChild(1)->IsTerminal(); /* if (HaveFreqCV) { if (HaveGapCV) { m_Pad.Process(bufsize, m_Output, GetChild(0)->GetOutput(), GetChild(1)->GetOutput()); } else { m_Pad.ProcessFM(bufsize, m_Output, GetChild(0)->GetOutput()); } } else { if (HaveGapCV) { m_Pad.Process(bufsize, m_Output, GetChild(1)->GetOutput()); } else {*/ m_Pad.Process(bufsize, m_Output); // } //} }
void KSNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(1) && ChildExists(2)) { if (GetChild(1)->IsTerminal()) { float c=GetChild(1)->GetValue(); if (c>=0 && c<1) m_KS.SetCutoff(c); } if (GetChild(2)->IsTerminal()) { float r=GetChild(2)->GetValue(); if (r>=0 && r<0.5) m_KS.SetResonance(r); } } m_KS.Process(bufsize, m_Output); }
bool Selector::ProcessStaticGeometry(Node *node, Virtual::StaticGeometry *geom) { if (geom) { if (geom->GetCpuCache().IsOnCpu()) { bool has_bsphere = false; bool has_bbox = false; Math::Line3D line = m_local_transform.top().Inversed() * m_view_ray; if (m_check_bounding_sphere) { const Math::BoundingSphere& sphere = geom->GetBoundingSphere(); Math::vec3 p1, p2; Math::Relation r = Math::CrossLineSphere(line, sphere, p1, p2); if (r == Math::Relation::INTERSECT_2) { std::vector<Math::vec3> p(2); p[0]= m_local_transform.top() * p1; p[1] = m_local_transform.top() * p2; Selection s; s.SetPoints(p); s.SetType(SelectionType::BoundingSphere); s.SetObject(node); m_selections.push_back(s); has_bsphere = true; } if (r == Math::Relation::INTERSECT_1) { std::vector<Math::vec3> p(1); p[0]= m_local_transform.top() * p1; Selection s; s.SetPoints(p); s.SetType(SelectionType::BoundingSphere); s.SetObject(node); m_selections.push_back(s); has_bsphere = true; } } if (m_check_bounding_box) { if (has_bsphere || !m_check_bounding_sphere) { const Math::BoundingBox& bbox = geom->GetBoundingBox(); Math::vec3 p; Math::Relation r = Math::CrossLineBoundingBox(line, bbox, p); if (r == Math::Relation::INTERSECT) { std::vector<Math::vec3> points(1); points[0] = m_local_transform.top() * p; Selection s; s.SetPoints(points); s.SetType(SelectionType::BoundingBox); s.SetObject(node); m_selections.push_back(s); has_bbox = true; } } } if (m_check_geometry) { if (has_bbox || !m_check_bounding_box) { std::vector<Math::vec3> points; std::vector<size_t> faces; Math::Relation r = Math::CrossLineTriangles(line, geom->GetCpuCache().GetVertices(), geom->GetCpuCache().GetFaces(), points, faces); if (r == Math::Relation::INTERSECT) { // return points to the worlds coordinate system for (auto& p : points) { p = m_local_transform.top() * p; } Selection selection; selection.SetPoints(points); selection.SetFaces(faces); selection.SetType(SelectionType::Geometry); selection.SetObject(node); m_selections.push_back(selection); } } } } } return ProcessChildren(node); }
bool Selector::ProcessSkinGeometry(Node *node, Virtual::SkinGeometry *value) { return ProcessChildren(node); }
void HoldNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && ChildExists(1)) { if (GetChild(0)->IsTerminal() && GetChild(1)->IsTerminal()) { if (GetChild(1)->GetValue() > 0) m_heldValue=GetChild(0)->GetValue(); for (unsigned int n=0; n<bufsize; n++) m_Output[n]=m_heldValue; } else if (!GetChild(0)->IsTerminal() && GetChild(1)->IsTerminal()) { if (GetChild(1)->GetValue() <= 0) { for (unsigned int n=0; n<bufsize; n++) m_Output[n]=m_heldValue; } else { switch (m_Type) { case SAMP: { for (unsigned int n=0; n<bufsize; n++) { if (m_lastCtrlVal <= 0) m_heldValue = GetChild(0)->GetOutput()[n]; m_lastCtrlVal = GetChild(1)->GetValue(); m_Output[n]=m_heldValue; } break; } case TRACK: { for (unsigned int n=0; n<bufsize; n++) { m_Output[n] = GetChild(0)->GetOutput()[n]; } break; } } } } else if (GetChild(0)->IsTerminal() && !GetChild(1)->IsTerminal()) { for (unsigned int n=0; n<bufsize; n++) { if (GetChild(1)->GetOutput()[n] > 0) { m_heldValue = GetChild(0)->GetValue(); } m_Output[n] = m_heldValue; } } else { switch (m_Type) { case SAMP: { for (unsigned int n=0; n<bufsize; n++) { if (m_lastCtrlVal <= 0 && GetChild(1)->GetOutput()[n] > 0) m_heldValue = GetChild(0)->GetOutput()[n]; m_lastCtrlVal = GetChild(1)->GetOutput()[n]; m_Output[n] = m_heldValue; } break; } case TRACK: { for (unsigned int n=0; n<bufsize; n++) { if (GetChild(1)->GetOutput()[n] > 0) m_heldValue = GetChild(0)->GetOutput()[n]; m_Output[n] = m_heldValue; } break; } } } } }
void XFadeNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && ChildExists(1) && ChildExists(2)) { if (GetChild(0)->IsTerminal()) { if (GetChild(1)->IsTerminal()) { if (GetChild(2)->IsTerminal()) { float value=0; float v0 = GetChild(0)->GetValue(); float v1 = GetChild(1)->GetValue(); float mix = GetChild(2)->GetValue(); if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); value = (v0 * (1 - mix)) + (v1 * mix); for (unsigned int n=0; n<bufsize; n++) m_Output[n]=value; } else { float v0 = GetChild(0)->GetValue(); float v1 = GetChild(1)->GetValue(); for (unsigned int n=0; n<bufsize; n++) { float mix = GetChild(2)->GetOutput()[n]; if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); m_Output[n]=(v0 * (1 - mix)) + (v1 * mix); } } } else { if (GetChild(2)->IsTerminal()) { float v0 = GetChild(0)->GetValue(); float mix = GetChild(2)->GetValue(); if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=(v0 * (1 - mix)) + (GetChild(1)->GetOutput()[n] * mix); } } else { float v0 = GetChild(0)->GetValue(); for (unsigned int n=0; n<bufsize; n++) { float mix = GetChild(2)->GetOutput()[n]; if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); m_Output[n]=(v0 * (1 - mix)) + (GetChild(1)->GetOutput()[n] * mix); } } } } else { if (GetChild(1)->IsTerminal()) { if (GetChild(2)->IsTerminal()) { float v1 = GetChild(1)->GetValue(); float mix = GetChild(2)->GetValue(); if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=(GetChild(0)->GetOutput()[n] * (1 - mix)) + (v1 * mix); } } else { float v1 = GetChild(1)->GetValue(); for (unsigned int n=0; n<bufsize; n++) { float mix = GetChild(2)->GetOutput()[n]; if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); m_Output[n]=(GetChild(0)->GetOutput()[n] * (1 - mix)) + (v1 * mix); } } } else { if (GetChild(2)->IsTerminal()) { float mix = GetChild(2)->GetValue(); if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=(GetChild(0)->GetOutput()[n] * (1 - mix)) + (GetChild(1)->GetOutput()[n] * mix); } } else { for (unsigned int n=0; n<bufsize; n++) { float mix = GetChild(2)->GetOutput()[n]; if (mix < -1) mix = -1; else if (mix > 1) mix = 1; mix = (0.5 + (mix * 0.5)); m_Output[n]=(GetChild(0)->GetOutput()[n] * (1 - mix)) + (GetChild(1)->GetOutput()[n] * mix); } } } } } }
void MathNode::Process(unsigned int bufsize) { if (bufsize>(unsigned int)m_Output.GetLength()) { m_Output.Allocate(bufsize); } ProcessChildren(bufsize); if (ChildExists(0) && ChildExists(1)) { if (GetChild(0)->IsTerminal() && GetChild(1)->IsTerminal()) { float value=0; float v0 = GetChild(0)->GetValue(); float v1 = GetChild(1)->GetValue(); switch(m_Type) { case ADD: value=v0+v1; break; case SUB: value=v0-v1; break; case MUL: value=v0*v1; break; case DIV: if (v1!=0) value=v0/v1; break; case POW: if (v0!=0 || v1>0) value=powf(v0,v1); break; }; for (unsigned int n=0; n<bufsize; n++) m_Output[n]=value; } else if (GetChild(0)->IsTerminal() && !GetChild(1)->IsTerminal()) { float v0 = GetChild(0)->GetValue(); switch(m_Type) { case ADD: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=v0+GetChild(1)->GetOutput()[n]; break; case SUB: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=v0-GetChild(1)->GetOutput()[n]; break; case MUL: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=v0*GetChild(1)->GetOutput()[n]; break; case DIV: { for (unsigned int n=0; n<bufsize; n++) { if (GetChild(1)->GetOutput()[n]!=0) { m_Output[n]=v0/GetChild(1)->GetOutput()[n]; } } } break; case POW: for (unsigned int n=0; n<bufsize; n++) { if (v0!=0 && GetChild(1)->GetOutput()[n]>0) { m_Output[n]=powf(v0,GetChild(1)->GetOutput()[n]); } } break; }; } else if (!GetChild(0)->IsTerminal() && GetChild(1)->IsTerminal()) { float v1 = GetChild(1)->GetValue(); switch(m_Type) { case ADD: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=GetChild(0)->GetOutput()[n]+v1; break; case SUB: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=GetChild(0)->GetOutput()[n]-v1; break; case MUL: for (unsigned int n=0; n<bufsize; n++) m_Output[n]=GetChild(0)->GetOutput()[n]*v1; break; case DIV: { if (v1!=0) { for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=GetChild(0)->GetOutput()[n]/v1; } } } break; case POW: for (unsigned int n=0; n<bufsize; n++) { if (GetChild(0)->GetOutput()[n]!=0 && v1>0) { m_Output[n]=powf(GetChild(0)->GetOutput()[n],v1); } } break; }; } else { switch(m_Type) { case ADD: { for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=GetChild(0)->GetOutput()[n]+GetChild(1)->GetOutput()[n]; } } break; case SUB: { for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=GetChild(0)->GetOutput()[n]-GetChild(1)->GetOutput()[n]; } } break; case MUL: { for (unsigned int n=0; n<bufsize; n++) { m_Output[n]=GetChild(0)->GetOutput()[n]*GetChild(1)->GetOutput()[n]; } } break; case DIV: { for (unsigned int n=0; n<bufsize; n++) { if (GetChild(1)->GetOutput()[n]!=0) { m_Output[n]=GetChild(0)->GetOutput()[n]/GetChild(1)->GetOutput()[n]; } } } break; case POW: { for (unsigned int n=0; n<bufsize; n++) { if (GetChild(0)->GetOutput()[n]!=0 && GetChild(1)->GetOutput()[n]>0) { m_Output[n]=powf(GetChild(0)->GetOutput()[n],GetChild(1)->GetOutput()[n]); } } } break; }; } } }