Exemple #1
0
void GeometryButton::Display(TimeValue t, ViewExp *vpt, int flags)
{
	if ( ! vpt || ! vpt->IsAlive() )
	{	
		// why are we here?
		DbgAssert(!_T("Doing Display() on invalid viewport!"));
		return;
	}

	//set the location before it's displayed.
	ResetLocation(vpt);
	if(vpt->IsActive()==TRUE &&vpt->GetHWnd()&&GetEnabled()==true)
	{
		MSTR st = GetLabel();
		vpt->getGW()->setRndLimits(vpt->getGW()->getRndMode() & ~GW_Z_BUFFER);
		vpt->getGW()->setColor(TEXT_COLOR, mColor);
		vpt->getGW()->wText(&IPoint3(mLocation.x,mLocation.y, 0), st.data()); //draw it undrneath the viewport text!
	}
}
int ConvexApproximationMouseCallBack::proc (ViewExp *vpt, int msg, int point, int flags, IPoint2 m, Matrix3& mat)
{
	if ((msg==MOUSE_POINT) || (msg==MOUSE_MOVE)) {
		m_obj->BuildMesh();

		// do not forget to select this source node again before leaving
		ConvexApproximationClassDesc* const desc = (ConvexApproximationClassDesc*) ConvexApproximationClassDesc::GetDescriptor();
		theHold.Begin();
		desc->m_currentInterface->SelectNode(desc->m_sourceNode, 1);
		MSTR undostr; undostr.printf("Select");
		theHold.Accept(undostr);

		return CREATE_STOP;
	} else {
		if ((msg == MOUSE_ABORT) || (msg == RIGHT_BUTTON)) {
			return CREATE_ABORT;
		}
	}
	return CREATE_CONTINUE;

}
void mrShaderButtonHandler::Update() {

	DbgAssert(m_dialogHWnd != NULL);

	HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
	ICustButton* custButton = GetICustButton(ctrlHWnd);
	if(custButton != NULL) {

		MSTR text;
		Texmap* shader = GetShader();
		if(shader != NULL)
			text = shader->GetFullName();
		else
			text = GetNoneString();

		custButton->SetText(text.data());
		
		ReleaseICustButton(custButton);
	}
	else {
		DbgAssert(false);
	}
}
const TCHAR * SlaveControlFloatClassDesc::ClassName()
{
    static MSTR class_name = MaxSDK::GetResourceStringAsMSTR(IDS_SLAVE_FLOAT_CLASS);
    return class_name.data();
}
const TCHAR * DaySlaveControlMatrix3ClassDesc::ClassName() 
{
	static MSTR name = MaxSDK::GetResourceStringAsMSTR(IDS_DAY_SLAVE_POS_CLASS);
	return name.data();
}
const TCHAR* NatLightAssemblyClassDesc::ClassName()
{ 
	static MSTR class_name = MaxSDK::GetResourceStringAsMSTR(IDS_NAT_LIGHT_NAME);
	return class_name.data();
}
AWDTexture *
AWDExporter::ExportTexture(AWD *awd, awd_ncache *ncache,Texmap* tex, Class_ID cid, int subNo, AWDMaterial * mat ) {

    AWDTexture *awd_tex;

    const char* name;
    int name_len;
    bool hasAlpha = false;

    MSTR path;

    awd_uint8 * buf;
    int buf_len;



    if (!tex) return NULL;
    if (tex->ClassID() != Class_ID(BMTEX_CLASS_ID, 0x00) ) return NULL;


    // texture already exist in cache
    awd_tex = (AWDTexture *)awd_ncache_get( ncache, tex );
    if( awd_tex ) return awd_tex;

    BitmapTex *bmptex = (BitmapTex*)tex;

    MaxSDK::AssetManagement::AssetUser asset = bmptex->GetMap();

    hasAlpha = bmptex->GetBitmap( GetStaticFrame() )->HasAlpha();

    if( !asset.GetFullFilePath(path) ) {
        fprintf( logfile, " export !asset.GetFullFilePath(path) : %i \n", asset.GetType() );
        fflush( logfile );

        //return NULL;
    }

    fprintf( logfile, " export  : %s \n", path );
    fflush( logfile );

    AWD_tex_type textype = EXTERNAL;

    if( GetIncludeMaps() &&
            asset.GetType() == MaxSDK::AssetManagement::kBitmapAsset
      ) {


        const char * dot;
        dot = strrchr(path,'.');




        if( !strcmp(dot, ".jpg")||
                !strcmp(dot, ".JPG")||
                !strcmp(dot, ".jpeg")||
                !strcmp(dot, ".JPEG")
          ) {
            textype = EMBEDDED_JPEG;
        } else if (
            !strcmp(dot, ".png")||
            !strcmp(dot, ".PNG")
        ) {
            textype = EMBEDDED_PNG;
        }



        if( textype == 0 ) {

            fprintf( logfile, " export texture : %s \n", path );
            fflush( logfile );
            // try to extract data
            Bitmap *bmp = bmptex->GetBitmap( GetStaticFrame() );

            BitmapInfo bi;

            MaxSDK::Util::Path *temppath;

            bi.SetWidth( bmp->Width() );
            bi.SetHeight( bmp->Height() );
            if( hasAlpha ) {
                bi.SetType( BMM_TRUE_32 );
                bi.SetFlags( MAP_HAS_ALPHA );
                path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.png";
                textype = EMBEDDED_PNG;
            } else {
                bi.SetType( BMM_TRUE_24 );
                path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.jpg";
                textype = EMBEDDED_JPEG;
            }

            temppath = new MaxSDK::Util::Path( path );
            bi.SetPath( *temppath );

            bmp->OpenOutput( & bi );
            bmp->Write( & bi );
            bmp->Close(& bi);

        }

        if( path != NULL ) {

            size_t result;

            int fd;
            errno_t err = _sopen_s( &fd, path, _O_RDONLY|_O_BINARY, _SH_DENYNO, _S_IREAD );

            if( err == 0 ) {

                struct stat *s;
                s = (struct stat *)malloc(sizeof(struct stat));
                fstat(fd, s);

                buf_len = s->st_size;
                buf = (awd_uint8 *) malloc (buf_len * sizeof( awd_uint8 ) );

                lseek(fd, 0, SEEK_SET);
                result = read(fd, buf, buf_len);


                if (result != buf_len) {
                    textype = EXTERNAL;
                }

                _close( fd );
            } else {
                textype = EXTERNAL;
            }
        }
    }

    name = tex->GetName();
    name_len = strlen( name );
    char* namecpy = (char*) malloc( name_len*sizeof( char ) ) ;
    strcpy( namecpy, name );

    awd_tex = new AWDTexture( textype, namecpy, name_len );

    if( textype != 0 ) {
        awd_tex->set_embed_data(buf, buf_len);
    }



    char * pathcpy = (char *) malloc( (path.length()+1) * sizeof( char ) );
    strcpy( pathcpy, path.data() );


    awd_tex->set_url( pathcpy, strlen( pathcpy ) );

    awd->add_texture( awd_tex );

    awd_ncache_add( ncache, tex, awd_tex );

    if( subNo == ID_DI ) {
        mat->set_texture( awd_tex );
        mat->alpha_blending = hasAlpha;
    }

    return awd_tex;
}
Exemple #8
0
/**
*  @brief
*    Writes the scene node modifiers
*/
void PLSceneNode::WriteModifiers(XmlElement &cSceneElement, const String &sApplicationDrive, const String &sApplicationDir)
{
	// Is there a 3ds Max node? (no 3ds Max node, no properties)
	INode *pMaxNode = GetMaxNode();
	if (pMaxNode) {
		// Has this 3ds Max node a target?
		if (pMaxNode->GetTarget()) {
			// Write down the scene node modifier
			WriteTargetRotationModifier(cSceneElement, *pMaxNode->GetTarget(), false);
		}

		// Are there any position, rotation, scale keyframes?
		bool bPositionKeyframes = false;
		bool bRotationKeyframes = false;
		bool bScaleKeyframes    = false;

		// Check 3ds Max node controllers
		Control *pTMController = pMaxNode->GetTMController();
		if (pTMController) {
			// Position controller
			Control *pController = pTMController->GetPositionController();
			if (pController) {
				// Are there any position keyframes?
				bPositionKeyframes = PLTools::HasKeyControlInterface(*pController);
				if (!bPositionKeyframes) {
					// Is there a path controller?
					IPathPosition *pPathController = GetIPathConstInterface(pController);
					if (pPathController && pPathController->GetNumTargets() > 0) {
						INode *pTarget = pPathController->GetNode(0);
						if (pTarget) {
							// Get path filename
							const String sPathFilename = PLTools::GetResourceFilename(PLTools::ResourcePath, String(pTarget->GetName()) + ".path");

							// Get the percentage along the path
							float fPercentageAlongPath = 0.0f;
							{
								IParamBlock2 *pIParamBlock2 = pPathController->GetParamBlock(path_params);
								int nRefNum = pIParamBlock2 ? pIParamBlock2->GetControllerRefNum(path_percent) : -1;
								RefTargetHandle cRefTargetHandle = (nRefNum >= 0) ? pIParamBlock2->GetReference(nRefNum) : nullptr;
								if (cRefTargetHandle)
									fPercentageAlongPath = pIParamBlock2->GetFloat(path_percent, 0);
							}

							{ // Add scene node modifier
								XmlElement *pModifierElement = new XmlElement("Modifier");
								pModifierElement->SetAttribute("Class",   "PLScene::SNMPositionPath");
								pModifierElement->SetAttribute("Filename", sPathFilename);
								pModifierElement->SetAttribute("Progress", String::Format("%f", fPercentageAlongPath));

								// [TODO] Any change to setup speed inside 3ds Max?
								static const float fSpeed = 0.03f;
								// Automatic animation playback?
								if (g_SEOptions.bAnimationPlayback)
									pModifierElement->SetAttribute("Speed", String::Format("%f", (pPathController->GetFlip() ? -fSpeed : fSpeed)));
								else
									pModifierElement->SetAttribute("Speed", "0.0");

								// Link modifier element
								cSceneElement.LinkEndChild(*pModifierElement);
							}

							// Follow?
							if (pPathController->GetFollow()) {
								// Add scene node modifier
								XmlElement *pModifierElement = new XmlElement("Modifier");
								pModifierElement->SetAttribute("Class",  "PLScene::SNMRotationMoveDirection");

								// Link modifier element
								cSceneElement.LinkEndChild(*pModifierElement);
							}
						}
					}
				}
			}

			// Rotation controller
			pController = pTMController->GetRotationController();
			if (pController) {
				// Are there any rotation keyframes?
				bRotationKeyframes = PLTools::HasKeyControlInterface(*pController);
				if (!bRotationKeyframes) {
					// Is there a look at controller?
					ILookAtConstRotation *pLookAtController = GetILookAtConstInterface(pController);
					if (pLookAtController && pLookAtController->GetNumTargets() > 0) {
						INode *pTarget = pLookAtController->GetNode(0);
						if (pTarget) {
							// Check look at controller
							bool bFlip = (pLookAtController->GetTargetAxisFlip() != 0);

							// Write down the scene node modifier
							WriteTargetRotationModifier(cSceneElement, *pTarget, bFlip);
						}
					}
				}
			}

			// Scale controller
			pController = pTMController->GetScaleController();
			if (pController) {
				// Are there any scale keyframes?
				bScaleKeyframes = PLTools::HasKeyControlInterface(*pController);
			}
		}

		// Export keyframes?
		if (bPositionKeyframes || bRotationKeyframes || bScaleKeyframes) {
			// Get timing
			Interval cInterval = GetCOREInterface()->GetAnimRange();
			int nTicksPerFrame = GetTicksPerFrame();
			int nFrameCount    = (cInterval.End() - cInterval.Start()) / nTicksPerFrame + 1;

			// Used to detect whether or not something is animated
			Point3 vFirstPos, vFirstScale;
			Quat qFirstRot;
			bool bUsePosition = false, bUseScale = false, bUseRotation = false;

			// Prepare the position chunk
			Chunk cPositionChunk;
			cPositionChunk.SetSemantic(Chunk::Position);
			cPositionChunk.Allocate(Chunk::Float, 3, nFrameCount);
			float *pfPositionData = reinterpret_cast<float*>(cPositionChunk.GetData());

			// Prepare the rotation chunk
			Chunk cRotationChunk;
			cRotationChunk.SetSemantic(Chunk::Rotation);
			cRotationChunk.Allocate(Chunk::Float, 4, nFrameCount);
			float *pfRotationData = reinterpret_cast<float*>(cRotationChunk.GetData());

			// Prepare the scale chunk
			Chunk cScaleChunk;
			cScaleChunk.SetSemantic(Chunk::Scale);
			cScaleChunk.Allocate(Chunk::Float, 3, nFrameCount);
			float *pfScaleData = reinterpret_cast<float*>(cScaleChunk.GetData());

			// Loop through all frames
			int nTime = cInterval.Start();
			for (int nFrame=0; nFrame<nFrameCount; nFrame++, nTime+=nTicksPerFrame) {
				// Get the position, rotation and scale
				Point3 vPos, vScale;
				Quat qRot;
				GetPosRotScale(vPos, qRot, vScale, nTime);

				// First frame?
				if (!nFrame) {
					vFirstPos   = vPos;
					vFirstScale = vScale;
					qFirstRot   = qRot;
				} else {
					if (!vFirstPos.Equals(vPos))
						bUsePosition = true;
					if (!vFirstScale.Equals(vScale))
						bUseScale = true;
					if (!qFirstRot.Equals(qRot))
						bUseRotation = true;
				}

				// Position
				if (bPositionKeyframes && pfPositionData) {
					// Currently ONLY the center of the container the node is in use used to make it relative
					const Point3 vParentWorldSpaceCenter = GetContainer() ? GetContainer()->GetWorldSpaceCenter() : Point3(0.0f, 0.0f, 0.0f);

					// Get the position
					const Point3 vFinalPos = (GetType() != TypeScene && GetType() != TypeCell) ? vPos-vParentWorldSpaceCenter : static_cast<const PLSceneContainer*>(this)->GetWorldSpaceCenter();

					// x
					*pfPositionData = vFinalPos.x;
					pfPositionData++;

					// y
					*pfPositionData = vFinalPos.y;
					pfPositionData++;

					// z
					*pfPositionData = vFinalPos.z;
					pfPositionData++;
				}

				// Rotation
				if (bRotationKeyframes && pfRotationData) {

					// [TODO] Check this (why do we need it?)
					qRot.Invert();

					// w
					*pfRotationData = qRot.w;
					pfRotationData++;

					// x
					*pfRotationData = qRot.x;
					pfRotationData++;

					// y
					*pfRotationData = qRot.y;
					pfRotationData++;

					// z
					*pfRotationData = qRot.z;
					pfRotationData++;
				}

				// Scale
				if (bScaleKeyframes && pfScaleData) {
					// x
					*pfScaleData = vScale.x;
					pfScaleData++;

					// y
					*pfScaleData = vScale.y;
					pfScaleData++;

					// z
					*pfScaleData = vScale.z;
					pfScaleData++;
				}
			}

			// Create keyframe animation scene node modifiers
			if (bPositionKeyframes && bUsePosition) {
				// [TODO] Better (and safer) filename
				// Save chunk
				const String sPositionKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_PositionKeyframes.chunk", GetName().GetASCII()).GetASCII());
				if (SaveChunk(cPositionChunk, sApplicationDrive + sApplicationDir + sPositionKeys)) {
					// Add the modifier
					XmlElement *pModifierElement = new XmlElement("Modifier");

					// Set class attribute
					pModifierElement->SetAttribute("Class", "PLScene::SNMPositionKeyframeAnimation");

					// [TODO] Currently the frame rate is by default always 24
					// Set frames per second attribute
	//				pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate());


					// Automatic animation playback?
					pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0");

					// Set keys attribute
					pModifierElement->SetAttribute("Keys", sPositionKeys);

					// Link modifier elements
					cSceneElement.LinkEndChild(*pModifierElement);
				}
			}
			if (bRotationKeyframes && bUseRotation) {
				// [TODO] Better (and safer) filename
				// Save chunk
				const String sRotationKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_RotationKeyframes.chunk", GetName().GetASCII()).GetASCII());
				if (SaveChunk(cRotationChunk, sApplicationDrive + sApplicationDir + sRotationKeys)) {
					// Add the modifier
					XmlElement *pModifierElement = new XmlElement("Modifier");

					// Set class attribute
					pModifierElement->SetAttribute("Class", "PLScene::SNMRotationKeyframeAnimation");

					// [TODO] Currently the frame rate is by default always 24
					// Set frames per second attribute
	//				pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate());

					// Automatic animation playback?
					pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0");

					// Set keys attribute
					pModifierElement->SetAttribute("Keys", sRotationKeys);

					// Link modifier elements
					cSceneElement.LinkEndChild(*pModifierElement);
				}
			}
			if (bScaleKeyframes && bUseScale) {
				// [TODO] Better (and safer) filename
				// Save chunk
				const String sScaleKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_ScaleKeyframes.chunk", GetName().GetASCII()).GetASCII());
				if (SaveChunk(cScaleChunk, sApplicationDrive + sApplicationDir + sScaleKeys)) {
					// Add the modifier
					XmlElement *pModifierElement = new XmlElement("Modifier");

					// Set class attribute
					pModifierElement->SetAttribute("Class", "PLScene::SNMScaleKeyframeAnimation");

					// [TODO] Currently the frame rate is by default always 24
					// Set frames per second attribute
	//				pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate());

					// Automatic animation playback?
					pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0");

					// Set keys attribute
					pModifierElement->SetAttribute("Keys", sScaleKeys);

					// Link modifier elements
					cSceneElement.LinkEndChild(*pModifierElement);
				}
			}
		}

		// Use modifiers?
		if (g_SEOptions.bUserPropModifiers) {
			// Check for modifiers
			MSTR sModifier;
			int nIndex = 1;
			TSTR s3dsMaxString;
			sModifier = _T("Mod");
			while (pMaxNode->GetUserPropString(sModifier, s3dsMaxString)) {
				// Add scene node modifier
				XmlElement *pModifierElement = new XmlElement("Modifier");

				// We really NEED a 'Class' attribute!
				bool bClassFound = false;

				// Get all expressions
				static RegEx cExpressionRegEx("\\s*((\\w*\\s*=\\s*\"[^\"]*\")|(\\w*\\s*=\\s*[\\w|]*))");
				const String sString = s3dsMaxString;
				uint32 nExpressionParsePos = 0;
				while (cExpressionRegEx.Match(sString, nExpressionParsePos)) {
					// Get expression
								 nExpressionParsePos = cExpressionRegEx.GetPosition();
					const String sExpression		 = cExpressionRegEx.GetResult(0);

					// Process the found expression
					static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*\"?\\s*([^\"]*)\\s*\"?");
					if (cRegEx.Match(sExpression)) {
						// Get name and value
						const String sName  = cRegEx.GetResult(0);
						const String sValue = cRegEx.GetResult(1);

						// Set attribute
						pModifierElement->SetAttribute(sName, sValue);

						// Class variable already found?
						if (!bClassFound && sName == "Class")
							bClassFound = true;
					}
				}

				// Link modifier element?
				if (bClassFound)
					cSceneElement.LinkEndChild(*pModifierElement);
				else 
					delete pModifierElement;

				// Get next modifier
				sModifier.printf(_T("Mod%d"), nIndex);
				nIndex++;
			}
		}
	}
}