MStatus setPlayback(double min, double max) { MStatus status = MS::kSuccess; MAnimControl anim; MTime minTime, maxTime, curTime; minTime.setValue(min); maxTime.setValue(max); status = anim.setMinTime(minTime); status = anim.setAnimationStartTime(minTime); if (max > 0) { status = anim.setMaxTime(maxTime); status = anim.setAnimationEndTime(maxTime); } return status; }
//---------------------------------------------------------------------------------------------------------------------- // This method should be overridden in user defined nodes. // Recompute the given output based on the nodes inputs. // The plug represents the data value that needs to be recomputed, and the data block holds the storage // for all of the node'_scale attributes. //---------------------------------------------------------------------------------------------------------------------- MStatus OceanNode::compute( const MPlug &_plug , MDataBlock &_data ){ MStatus status; // see if we get the output plug if( _plug == m_output){ MDataHandle dataHandle; dataHandle = _data.inputValue(m_resolution, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for resolution plug"); if (m_res != dataHandle.asInt()){ switch(dataHandle.asInt()){ case 0: m_ocean->setResolution(128); MGlobal::displayInfo("Resolution: 128"); break; case 1: m_ocean->setResolution(256); MGlobal::displayInfo("Resolution: 256"); break; case 2: m_ocean->setResolution(512); MGlobal::displayInfo("Resolution: 512"); break; case 3: m_ocean->setResolution(1024); MGlobal::displayInfo("Resolution: 1024"); break; default: break; } m_res = dataHandle.asInt(); } dataHandle = _data.inputValue( m_amplitude , &status ); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for amplitude plug" ); // now get the value for the data handle as a double double amp = dataHandle.asDouble(); m_ocean->setAmplitude(amp); dataHandle = _data.inputValue(m_frequency, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get handle for \"frequency\" plug"); double freq = dataHandle.asDouble(); m_ocean->setFrequency(freq); dataHandle = _data.inputValue(m_windDirectionX, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionX plug"); // now get value for data handle double wdx = dataHandle.asDouble(); dataHandle = _data.inputValue(m_windDirectionZ, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionY plug"); // now get value for data handle double wdz = dataHandle.asDouble(); m_ocean->setWindVector(make_float2(wdx, wdz)); dataHandle = _data.inputValue(m_windSpeed, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windSpeed plug"); // now get value for data handle double ws = dataHandle.asDouble(); m_ocean->setWindSpeed(ws); // Only create a new frequency domain if either amplitude or the wind vecotr has changed if (m_amp != amp || m_wdx != wdx || m_wdz != wdz || m_ws != ws ){ MGlobal::displayInfo("here"); m_ocean->createH0(); m_amp = amp; m_wdx = wdx; m_wdz = wdz; m_ws = ws; } dataHandle = _data.inputValue(m_choppiness, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for the choppiness plug"); double choppiness = dataHandle.asDouble(); dataHandle = _data.inputValue(m_time, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for time plug"); MTime time = dataHandle.asTime(); MDataHandle outputData = _data.outputValue(m_output, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for output plug" ); MFnMeshData mesh; MObject outputObject = mesh.create(&status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to create output mesh"); // Find the current frame number we're on and create the grid based on this MAnimControl anim; anim.setMinTime(time); createGrid((int)pow(2.0, m_res+7), anim.currentTime().value()/24, choppiness, outputObject, status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to to create grid"); outputData.set(outputObject); // clean the output plug, ie unset it from dirty so that maya does not re-evaluate it _data.setClean( _plug ); return MStatus::kSuccess; } return MStatus::kUnknownParameter; }