Пример #1
0
int		LinkTimeControl::HitTestFCurves( ParamDimensionBase *dim, TrackHitTab& hits, Rect& rcHit, Rect& rcGraph,			
			float tzoom, int tscroll, float vzoom, int vscroll, DWORD flags )
{
	int h = rcGraph.h()-1;

	bool hit = false;

	const int n = NumKeys();
	for ( int i=0; i<n; ++i )
	{
		BOOL sel = IsKeySelected( i );
		if ( ( flags & HITTRACK_SELONLY ) && !sel )
			continue;
		if ( ( flags & HITTRACK_UNSELONLY ) && sel )
			continue;
		TimeValue t = GetKeyTime( i );
		int x = TimeToScreen( t, tzoom, tscroll );
		float val;
		Interval valid;
		GetValue( t, &val, valid );
		int y = ValueToScreen( dim->Convert(val), h, vzoom, vscroll );
		if ( rcHit.Contains( IPoint2( x, y ) ) )
		{
			hit = true;
			TrackHitRecord rec( i, 0 );
			hits.Append( 1, &rec );
			if ( flags & HITTRACK_ABORTONHIT )
				break;
		}
	}

	return hit ?  HITCURVE_KEY : HITCURVE_NONE;
}
Пример #2
0
void ESMBackspaceUser::Notify() {
	if(spline->KnotCount() > 2) {
		// Tell the spline we just backspaced to remove the last point
		spline->Create(NULL, -1, 0, 0, IPoint2(0,0), NULL);
		mod->createShapeData->Invalidate(PART_GEOM);
		mod->NotifyDependents(FOREVER, PART_GEOM, REFMSG_CHANGE);
		mod->ip->RedrawViews(mod->ip->GetTime(), REDRAW_NORMAL);
		}
	}
Пример #3
0
void BGContext::SetScreenPos(int x, int y, int width, int height)
{
	SCDebugPrint("BGContext::SetScreenPos\n");
	iscr = IPoint2(x,y);
	scrPos.x = float(x)-globContext->xc;
	scrPos.y = float(y)-globContext->yc;

	cpos = BGGetPoint();
	viewDir = globContext->projType ?  Point3(0.0f,0.0f,-1.0f) : Normalize(cpos);
}
Пример #4
0
RISE::RISEPel MAXBSDF::value( const RISE::Vector3& vLightIn, const RISE::RayIntersectionGeometric& ri ) const
{
	HitInfo* hitInfo = dynamic_cast<HitInfo*>( ri.pCustom );
	if( hitInfo ) {
		// We have to first setup the shade context, then we just route this call to the MAX material
		// Shade point
		Face* f = &(hitInfo->instance->mesh->faces[hitInfo->faceNum]);
		MtlID mid = 0;
		int nNumSubs = hitInfo->instance->mtl->NumSubMtls();

		if (nNumSubs) {
			// Get sub material ID of the face.
			mid = f->getMatID();
			// the material ID of the face can be larger than the
			// total number of sub materials (because it is user
			// configurable).
			// Here I use a modulus function to bring the number
			// down to a legal value.
			mid = mid % nNumSubs;
		}

		const Point3 viewDir = VectorTransform(renderer->view.affineTM, RISE2MAXVector(ri.ray.dir));
		const Point3 viewCam = renderer->view.affineTM * RISE2MAXPoint(ri.ray.origin);

		lightDir = VectorTransform(renderer->view.affineTM, RISE2MAXVector(vLightIn));

		// Shade the face that was closest to the camera
		sc.SetViewDir( viewDir );
		sc.bc->SetViewDir( viewDir );
		sc.SetScreenPos(IPoint2(ri.rast.x, ri.rast.y));
		sc.SetCamPos( viewCam );
		sc.bc->SetCamPos( viewCam );
		sc.bc->SetScreenPos(ri.rast.x, ri.rast.y, rparams->devWidth, rparams->devHeight);
		sc.SetInstance(hitInfo->instance);
		sc.SetMtlNum(mid);
		sc.SetFaceNum(hitInfo->faceNum);
		sc.SetHitPos(renderer->view.affineTM * RISE2MAXPoint(ri.ptIntersection));
		sc.SetBary(hitInfo->baryCoord);
		sc.CalcNormals();

		// Go off and do the actual shading.
		hitInfo->instance->mtl->Shade(sc);	

		const Color result = sc.out.c;

		// We cannot handle transparency here unfortunately, Need to come up with a way to do this

		// The compensation factor is account for the diffuseCoef we told MAX and for the PI factor 
		const RISE::Scalar compensation_factor = 1.0 / (PI * RISE::Vector3Ops::Dot( vLightIn, ri.vNormal ));
		return RISE::RISEPel( result.r*compensation_factor, result.g*compensation_factor, result.b*compensation_factor );	
	}

	return RISE::RISEPel(0,0,0);
}
Пример #5
0
/**
 * This method will be called from the max system when the user
 * has choosen to export to the OpenSceneGraph format.
 * This method is the entry point to the exporter plugin.
 */
int	OSGExp::DoExport(const TCHAR *name, ExpInterface *ei,
					 Interface *i, BOOL suppressPrompts, DWORD MAXOptions){

	// Only support "one at the time" exporting.
	if(isExporting){
		return FALSE;
	}
	isExporting = TRUE;

	// Grab the interface pointer and save it for later use.
	_ip = i;

	// Set export path in options class
	TCHAR p[300];
	TCHAR f[100];
	TCHAR e[10];
	BMMSplitFilename(name, p, f, e);
	_options->setExportPath(p);
	_options->setExportFilename(f);
	_options->setExportExtension(e);

	// Get filename to config file.
	TSTR cfgfilename = _ip->GetDir(APP_PLUGCFG_DIR);;
	cfgfilename += _T("\\OSGEXP.CFG");

	// Load options from config file
	_options->load(cfgfilename);

	// Should we only export selected nodes?
	_onlyExportSelected = (MAXOptions & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Show option dialog to user and retrive any possible plugin choices.
	if(!suppressPrompts)
		if(!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_EXPORTBOX), 
				           GetActiveWindow(), OptionsDlgProc,
						   (LPARAM)_options)){
			// If user closed or canceled export box then shutdown plugin.
			isExporting = FALSE;
			return TRUE;
		}

	// Write options to config file.
	_options->write(cfgfilename);

	// Create OSG root transform to hold the scene.
{	
	osg::ref_ptr<osg::MatrixTransform> rootTransform = new osg::MatrixTransform();
	//osg::MatrixTransform* rootTransform = new osg::MatrixTransform();
	rootTransform->setName(std::string(_ip->GetRootNode()->GetName()));
	// Set static datavariance for better performance
	rootTransform->setDataVariance(osg::Object::STATIC);
	// Set NodeMask
	if(_options->getUseDefaultNodeMaskValue())
		rootTransform->setNodeMask(_options->getDefaultNodeMaskValue());
	osg::Matrix rootMat = getNodeTransform(_ip->GetRootNode(), _ip->GetTime());
	rootTransform->setMatrix(rootMat);
    // Create root stateset for the lights.
	osg::ref_ptr<osg::StateSet> rootStateSet = new osg::StateSet();
	// Turn of lighting if set by the user.
	if(_options->getTurnOffLighting())
		rootStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
	else
		rootStateSet->setMode(GL_LIGHTING,osg::StateAttribute::ON);
	//osg::StateSet* rootStateSet = new osg::StateSet();
    rootTransform->setStateSet(rootStateSet.get());


	// We will make two progress bars. The first one will show
	// the exporting of materials, wheras the second one will show
	// the exporting of nodes. To get the total number of nodes in the
	// scene graph we will accumulate the total node count while
	// preprocessing the scenegraph for materials.
	_nTotalNodeCount = 0;
	_nCurNode = 0;
	_nTotalMtlCount = _ip->GetSceneMtls()->Count();
	_nCurMtl = 0;

	// Starting up the material exporting progress bar.
	_ip->ProgressStart(_T("Exporting materials..."), TRUE, fn, NULL);
	// Export materials by preprocessing the scenegraph. 
	if(!preProcess(_ip->GetRootNode(), _ip->GetTime())){
		// If user cancels we stop progress bar and return.
		_ip->ProgressEnd();
		isExporting = FALSE;
		return TRUE;
	}
	// We're done exporting materials. Finish the progress bar.
	_ip->ProgressEnd();

	// Starting up the node exporting progress bar.
	_ip->ProgressStart(_T("Exporting scene..."), TRUE, fn, NULL);

	// Get number of children for the root node in the interface.
	int numChildren = _ip->GetRootNode()->NumberOfChildren();
	
	// Call our node enumerator.
	// The nodeEnum function will recurse into itself and 
	// export each object found in the scene.
	for (int idx=0; idx<numChildren; idx++) {
		if (_ip->GetCancel() || !nodeEnum(rootTransform.get(), _ip->GetRootNode()->GetChildNode(idx), rootTransform.get())){
			// If user cancels we stop progress bar and return
			_ip->ProgressEnd();
			isExporting = FALSE;
			return TRUE;
		}
	}
	// Finish exporting progress bar
	_ip->ProgressEnd();


	// If optimize scene graph
	unsigned int optimizeMask = 0;
	if(_options->getTriStripGeometry())
		optimizeMask |= osgUtil::Optimizer::TRISTRIP_GEOMETRY;
	if(_options->getMergeGeometry())
		optimizeMask |= osgUtil::Optimizer::MERGE_GEOMETRY;
	if(_options->getFlattenStaticTransform())
		optimizeMask |= osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS;
	if(_options->getShareDuplicateStates())
		optimizeMask |= osgUtil::Optimizer::SHARE_DUPLICATE_STATE;
	if(_options->getSpatializeGroups())
		optimizeMask |= osgUtil::Optimizer::SPATIALIZE_GROUPS;
	if(optimizeMask){
		_ip->ProgressStart(_T("Optimizing scenegraph..."), FALSE, fn, NULL);
		_ip->ProgressUpdate(0.5f); 
		osgUtil::Optimizer optimizer;
		optimizer.optimize(rootTransform.get(), optimizeMask);
		_ip->ProgressEnd();
	}
	 
	// Save file to disk.
	if(_options->getSaveFile()){
		_ip->ProgressStart(_T("Writing file..."), FALSE, fn, NULL);
		_ip->ProgressUpdate(0.5f); 
		if(_options->getExportExtension().compare(".osg")==0 ||
		   _options->getExportExtension().compare(".OSG")==0 ||
		   _options->getExportExtension().compare(".ive")==0 ||
		   _options->getExportExtension().compare(".IVE")==0   ){

			std::string filename(name);

			// Exclude image data from ive file if this options has been choosen
			if(!_options->getIncludeImageDataInIveFile()){
				osgDB::ReaderWriter::Options* opt = new osgDB::ReaderWriter::Options("noTexturesInIVEFile");
				osgDB::Registry::instance()->setOptions(opt);
			}


#if defined(OPENSCENEGRAPH_MAJOR_VERSION) && OPENSCENEGRAPH_MAJOR_VERSION >= 2 && defined(OPENSCENEGRAPH_MINOR_VERSION) && OPENSCENEGRAPH_MINOR_VERSION >= 4
            osgDB::ReaderWriter::WriteResult res = 
               osgDB::Registry::instance()->writeNode(*rootTransform, filename, NULL);
#else
            osgDB::ReaderWriter::WriteResult res = 
               osgDB::Registry::instance()->writeNode(*rootTransform, filename);
#endif

			if(res.error() && _options->getShowErrMsg()){
				static TCHAR szBuffer[256];
				wsprintf(szBuffer,TEXT("Error writing file %s:\n%s"), 
					     TEXT(filename.c_str()),res.message());
				MessageBox (GetActiveWindow(), szBuffer, TEXT("Warning"),
					        MB_OK | MB_ICONWARNING) ;
			}

			if(!_options->getIncludeImageDataInIveFile()){
                // Turn readerwriter options off again.
				osgDB::ReaderWriter::Options* opt = new osgDB::ReaderWriter::Options();
				osgDB::Registry::instance()->setOptions(opt);
            }
		}
		else{
			if(_options->getShowErrMsg()){
				std::string error("Can not find plugin to save file: ");
				error.append(name);
				MessageBox (GetActiveWindow(), error.c_str() , TEXT("Warning"), MB_OK | MB_ICONWARNING) ;
			}
		}
		_ip->ProgressEnd();
	}

	// Show quick preview
	if(_options->getQuickView()){

		float fNear = 1.0f;
		float fFar = 1000.0f;

		// Get the active viewport and the win32 window within it.
		// The position and size will be retreive from this.
		ViewExp* viewExp = _ip->GetActiveViewport();
		float fov = viewExp->GetFOV();
		HWND hWnd = viewExp->getGW()->getHWnd();
		RECT sRect;
		BOOL ok = GetWindowRect(hWnd, &sRect);
		int width = 100;
		int height = 100;
		int x =100;
		int y =100;
		if(ok){
			x = sRect.left;
			y = sRect.top;
			width = sRect.right - sRect.left;
			height = sRect.bottom - sRect.top;
		}

		// Create previewer window and set size.
		Previewer previewer;
		previewer.setWindowSize(x, y, width, height);


		// The affine TM transforms from world coords to view coords
		// so we need the inverse of this matrix
		Matrix3 aTM, camTM, coordSysTM;
		Point3 viewDir, viewPos, lookAtPos, upVector;
		INode* camera;
		float dist = 100;

		Point3 upperLeft = viewExp->MapScreenToView(IPoint2(0, 0), fFar);
		Point3 lowerRight = viewExp->MapScreenToView(IPoint2(width, height), fFar);
		
		viewExp->GetAffineTM(aTM);
		coordSysTM = Inverse(aTM);	

		viewDir = coordSysTM.VectorTransform(Point3(0.0f, 0.0f, -1.0f));
		viewPos = coordSysTM.GetRow(3);
		lookAtPos = viewPos + viewDir;
		upVector.Set(0.0f, 0.0f, 1.0f);

		switch(viewExp->GetViewType()){
			case VIEW_ISO_USER:
			case VIEW_PERSP_USER:
				previewer.setProjectionMatrixAsFrustum(lowerRight.x, upperLeft.x,  upperLeft.y, lowerRight.y, fFar, -fFar);
				break;
			case VIEW_CAMERA:
				previewer.setProjectionMatrixAsFrustum(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, fFar, -fFar);
				camera = viewExp->GetViewCamera();
				camTM = camera->GetObjTMBeforeWSM(_ip->GetTime());
				viewDir = camTM.VectorTransform(Point3(0.0f, 0.0f, -1.0f));
				viewPos = camTM.GetRow(3);
				lookAtPos = viewPos + viewDir;
				break;
			case VIEW_LEFT:
			case VIEW_RIGHT:
			case VIEW_TOP:
			case VIEW_BOTTOM:
			case VIEW_FRONT:
			case VIEW_BACK:
				previewer.setProjectionMatrixAsOrtho(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, -fFar, fFar);
				//cam->setOrtho(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, -fFar, fFar);
				// Go far away from the viewing point in the negative viewing direction.
				viewPos = coordSysTM.PointTransform(Point3(0.0f, 0.0f, fFar));
				lookAtPos = viewPos + viewDir;
				// In top view the up vector on the camera is the positive y-axis.
				if(viewExp->GetViewType() == VIEW_TOP)
					upVector.Set(0.0f, 1.0f, 0.0f);
				// In bottom view the up vector on the camera is the negative y-axis.
				if(viewExp->GetViewType() == VIEW_BOTTOM)
					upVector.Set(0.0f, -1.0f, 0.0f);
				break;
		}
		// When we are done with the viewport we should release it.
		_ip->ReleaseViewport(viewExp);

		// Set scene data.
		previewer.setSceneData(rootTransform.get());

		// set the view - OpenGL look at
		previewer.setViewMatrixAsLookAt(osg::Vec3( viewPos.x, viewPos.y, viewPos.z),
										 osg::Vec3(lookAtPos.x, lookAtPos.y, lookAtPos.z),
										 osg::Vec3(upVector.x, upVector.y, upVector.z) );
 		previewer.run();

		isExporting = FALSE;
		return TRUE;
	}
}
	isExporting = FALSE;
	return TRUE;
}
Пример #6
0
bool vtElevLayer::WriteElevationTileset(TilingOptions &opts, BuilderView *pView)
{
	// Avoid trouble with '.' and ',' in Europe
	ScopedLocale normal_numbers(LC_NUMERIC, "C");

	// Check that options are valid
	CheckCompressionMethod(opts);

	// grid size
	int base_tilesize = opts.lod0size;

	int gridcols, gridrows;
	m_pGrid->GetDimensions(gridcols, gridrows);

	DRECT area = m_pGrid->GetEarthExtents();
	DPoint2 tile_dim(area.Width()/opts.cols, area.Height()/opts.rows);
	DPoint2 cell_size = tile_dim / base_tilesize;

	const vtProjection &proj = m_pGrid->GetProjection();
	vtString units = GetLinearUnitName(proj.GetUnits());
	units.MakeLower();
	int zone = proj.GetUTMZone();
	vtString crs;
	if (proj.IsGeographic())
		crs = "LL";
	else if (zone != 0)
		crs = "UTM";
	else
		crs = "Other";

	// Try to create directory to hold the tiles
	vtString dirname = opts.fname;
	RemoveFileExtensions(dirname);
	if (!vtCreateDir(dirname))
		return false;

	// We won't know the exact height extents until the tiles have generated,
	//  so gather extents as we produce the tiles and write the INI later.
	float minheight = 1E9, maxheight = -1E9;

	ColorMap cmap;
	vtElevLayer::SetupDefaultColors(cmap);	// defaults
	vtString dirname_image = opts.fname_images;
	RemoveFileExtensions(dirname_image);
	if (opts.bCreateDerivedImages)
	{
		if (!vtCreateDir(dirname_image))
			return false;

		vtString cmap_fname = opts.draw.m_strColorMapFile;
		vtString cmap_path = FindFileOnPaths(vtGetDataPath(), "GeoTypical/" + cmap_fname);
		if (cmap_path == "")
			DisplayAndLog("Couldn't find color map.");
		else
		{
			if (!cmap.Load(cmap_path))
				DisplayAndLog("Couldn't load color map.");
		}
	}

	ImageGLCanvas *pCanvas = NULL;
#if USE_OPENGL
	wxFrame *frame = new wxFrame;
	if (opts.bCreateDerivedImages && opts.bUseTextureCompression && opts.eCompressionType == TC_OPENGL)
	{
		frame->Create(g_bld->m_pParentWindow, -1, _T("Texture Compression OpenGL Context"),
			wxPoint(100,400), wxSize(280, 300), wxCAPTION | wxCLIP_CHILDREN);
		pCanvas = new ImageGLCanvas(frame);
	}
#endif

	// make a note of which lods exist
	LODMap lod_existence_map(opts.cols, opts.rows);

	bool bFloat = m_pGrid->IsFloatMode();
	bool bJPEG = (opts.bUseTextureCompression && opts.eCompressionType == TC_JPEG);

	int i, j, lod;
	int total = opts.rows * opts.cols, done = 0;
	for (j = 0; j < opts.rows; j++)
	{
		for (i = 0; i < opts.cols; i++)
		{
			// We might want to skip certain tiles
			if (opts.iMinRow != -1 &&
				(i < opts.iMinCol || i > opts.iMaxCol ||
				 j < opts.iMinRow || j > opts.iMaxRow))
				continue;

			DRECT tile_area;
			tile_area.left = area.left + tile_dim.x * i;
			tile_area.right = area.left + tile_dim.x * (i+1);
			tile_area.bottom = area.bottom + tile_dim.y * j;
			tile_area.top = area.bottom + tile_dim.y * (j+1);

			int col = i;
			int row = opts.rows-1-j;

			// draw our progress in the main view
			if (pView)
				pView->ShowGridMarks(area, opts.cols, opts.rows, col, opts.rows-1-row);

			// Extract the highest LOD we need
			vtElevationGrid base_lod(tile_area, IPoint2(base_tilesize+1, base_tilesize+1),
				bFloat, proj);

			bool bAllInvalid = true;
			bool bAllZero = true;
			int iNumInvalid = 0;
			DPoint2 p;
			int x, y;
			for (y = base_tilesize; y >= 0; y--)
			{
				p.y = area.bottom + (j*tile_dim.y) + ((double)y / base_tilesize * tile_dim.y);
				for (x = 0; x <= base_tilesize; x++)
				{
					p.x = area.left + (i*tile_dim.x) + ((double)x / base_tilesize * tile_dim.x);

					float fvalue = m_pGrid->GetFilteredValue(p);
					base_lod.SetFValue(x, y, fvalue);

					if (fvalue == INVALID_ELEVATION)
						iNumInvalid++;
					else
					{
						bAllInvalid = false;

						// Gather height extents
						if (fvalue < minheight)
							minheight = fvalue;
						if (fvalue > maxheight)
							maxheight = fvalue;
					}
					if (fvalue != 0)
						bAllZero = false;
				}
			}
			// Increment whether we omit or not
			done++;

			// If there is no real data there, omit this tile
			if (bAllInvalid)
				continue;

			// Omit all-zero tiles (flat sea-level) if desired
			if (opts.bOmitFlatTiles && bAllZero)
				continue;

			// Now we know this tile will be included, so note the LODs present
			int base_tile_exponent = vt_log2(base_tilesize);
			lod_existence_map.set(i, j, base_tile_exponent, base_tile_exponent-(opts.numlods-1));

			if (iNumInvalid > 0)
			{
				UpdateProgressDialog2(done*99/total, 0, _("Filling gaps"));

				bool bGood;
				int method = g_Options.GetValueInt(TAG_GAP_FILL_METHOD);
				if (method == 1)
					bGood = base_lod.FillGaps(NULL, progress_callback_minor);
				else if (method == 2)
					bGood = base_lod.FillGapsSmooth(NULL, progress_callback_minor);
				else if (method == 3)
					bGood = (base_lod.FillGapsByRegionGrowing(2, 5, progress_callback_minor) != -1);
				if (!bGood)
					return false;

				opts.iNoDataFilled += iNumInvalid;
			}

			// Create a matching derived texture tileset
			if (opts.bCreateDerivedImages)
			{
				// Create a matching derived texture tileset
				vtDIB dib;
				base_lod.ComputeHeightExtents();

				if (opts.bImageAlpha)
				{
					dib.Create(IPoint2(base_tilesize, base_tilesize), 32);
					base_lod.ColorDibFromElevation(&dib, &cmap, 4000, RGBAi(0,0,0,0));
				}
				else
				{
					dib.Create(IPoint2(base_tilesize, base_tilesize), 24);
					base_lod.ColorDibFromElevation(&dib, &cmap, 4000, RGBi(255,0,0));
				}

				if (opts.draw.m_bShadingQuick)
					base_lod.ShadeQuick(&dib, SHADING_BIAS, true);
				else if (opts.draw.m_bShadingDot)
				{
					FPoint3 light_dir = LightDirection(opts.draw.m_iCastAngle,
						opts.draw.m_iCastDirection);

					// Don't cast shadows for tileset; they won't cast
					//  correctly from one tile to the next.
					base_lod.ShadeDibFromElevation(&dib, light_dir, 1.0f,
						opts.draw.m_fAmbient, opts.draw.m_fGamma, true);
				}

				for (int k = 0; k < opts.numlods; k++)
				{
					vtString fname = MakeFilenameDB(dirname_image, col, row, k);

					int tilesize = base_tilesize >> k;

					vtMiniDatabuf output_buf;
					output_buf.xsize = tilesize;
					output_buf.ysize = tilesize;
					output_buf.zsize = 1;
					output_buf.tsteps = 1;
					output_buf.SetBounds(proj, tile_area);

					int depth = dib.GetDepth() / 8;
					int iUncompressedSize = tilesize * tilesize * depth;
					uchar *rgb_bytes = (uchar *) malloc(iUncompressedSize);

					uchar *dst = rgb_bytes;
					if (opts.bImageAlpha)
					{
						RGBAi rgba;
						for (int ro = 0; ro < base_tilesize; ro += (1<<k))
							for (int co = 0; co < base_tilesize; co += (1<<k))
							{
								dib.GetPixel32(co, ro, rgba);
								*dst++ = rgba.r;
								*dst++ = rgba.g;
								*dst++ = rgba.b;
								*dst++ = rgba.a;
							}
					}
					else
					{
						RGBi rgb;
						for (int ro = 0; ro < base_tilesize; ro += (1<<k))
							for (int co = 0; co < base_tilesize; co += (1<<k))
							{
								dib.GetPixel24(co, ro, rgb);
								*dst++ = rgb.r;
								*dst++ = rgb.g;
								*dst++ = rgb.b;
							}
					}

					// Write and optionally compress the image
					WriteMiniImage(fname, opts, rgb_bytes, output_buf,
						iUncompressedSize, pCanvas);

					// Free the uncompressed image
					free(rgb_bytes);
				}
			}

			for (lod = 0; lod < opts.numlods; lod++)
			{
				int tilesize = base_tilesize >> lod;

				vtString fname = MakeFilenameDB(dirname, col, row, lod);

				// make a message for the progress dialog
				wxString msg;
				msg.Printf(_("Writing tile '%hs', size %dx%d"),
					(const char *)fname, tilesize, tilesize);
				UpdateProgressDialog2(done*99/total, 0, msg);

				vtMiniDatabuf buf;
				buf.SetBounds(proj, tile_area);
				buf.alloc(tilesize+1, tilesize+1, 1, 1, bFloat ? 2 : 1);
				float *fdata = (float *) buf.data;
				short *sdata = (short *) buf.data;

				DPoint2 p;
				for (int y = base_tilesize; y >= 0; y -= (1<<lod))
				{
					p.y = area.bottom + (j*tile_dim.y) + ((double)y / base_tilesize * tile_dim.y);
					for (int x = 0; x <= base_tilesize; x += (1<<lod))
					{
						p.x = area.left + (i*tile_dim.x) + ((double)x / base_tilesize * tile_dim.x);

						if (bFloat)
						{
							*fdata = base_lod.GetFilteredValue(p);
							fdata++;
						}
						else
						{
							*sdata = (short) base_lod.GetFilteredValue(p);
							sdata++;
						}
					}
				}
				if (buf.savedata(fname) == 0)
				{
					// what should we do if writing a tile fails?
				}
			}
		}
	}
Пример #7
0
//! Tells the shader to apply shade to the given intersection point
void MAXShaderOp::PerformOperation( 
	const RISE::RayIntersection& ri,					///< [in] Intersection information 
	const RISE::IRayCaster& caster,					///< [in] The Ray Caster to use for all ray casting needs
	const RISE::IRayCaster::RAY_STATE& rs,			///< [in] Current ray state
	RISE::RISEPel& c,									///< [in/out] Resultant color from op
	const RISE::IORStack* const ior_stack,			///< [in/out] Index of refraction stack
	const RISE::ScatteredRayContainer* pScat,			///< [in] Scattering information
	const RISE::RandomNumberGenerator& random			///< [in] Random number generator
	) const
{
	HitInfo* hitInfo = dynamic_cast<HitInfo*>( ri.geometric.pCustom );
	if( hitInfo ) {
		// We have to first setup the shade context, then we just route this call to the MAX material
		// Shade point
		Face* f = &(hitInfo->instance->mesh->faces[hitInfo->faceNum]);
		MtlID mid = 0;
		int nNumSubs = hitInfo->instance->mtl->NumSubMtls();

		if (nNumSubs) {
			// Get sub material ID of the face.
			mid = f->getMatID();
			// the material ID of the face can be larger than the
			// total number of sub materials (because it is user
			// configurable).
			// Here I use a modulus function to bring the number
			// down to a legal value.
			mid = mid % nNumSubs;
		}

		const Point3 viewDir = VectorTransform(renderer->view.affineTM, RISE2MAXVector(ri.geometric.ray.dir));
		const Point3 viewCam = renderer->view.affineTM * RISE2MAXPoint(ri.geometric.ray.origin);

		// Shade the face that was closest to the camera
		sc.SetViewDir( viewDir );
		sc.bc->SetViewDir( viewDir );
		sc.SetScreenPos(IPoint2(ri.geometric.rast.x, ri.geometric.rast.y));
		sc.SetCamPos( viewCam );
		sc.bc->SetCamPos( viewCam );
		sc.bc->SetScreenPos(ri.geometric.rast.x, ri.geometric.rast.y, rparams->devWidth, rparams->devHeight);
		sc.SetInstance(hitInfo->instance);
		sc.SetMtlNum(mid);
		sc.SetFaceNum(hitInfo->faceNum);
		sc.SetHitPos(renderer->view.affineTM * RISE2MAXPoint(ri.geometric.ptIntersection));
		sc.SetBary(hitInfo->baryCoord);
		sc.CalcNormals();
		sc.pRayCaster = &caster;
		sc.affineTM = renderer->view.affineTM;
		sc.worldPtIntersection = RISE2MAXPoint(ri.geometric.ptIntersection);

		// Go off and do the actual shading.
		hitInfo->instance->mtl->Shade(sc);	

		Color result = sc.out.c;

		// Handle transparency
		if( sc.out.t.r > 0 || sc.out.t.g > 0 || sc.out.t.b > 0 ) {
			// There is transparency, shoot a continuing ray
			RISE::Ray ray = ri.geometric.ray;
			ray.Advance( ri.geometric.range+2e-8 );

			RISE::RISEPel cthis;
			if( caster.CastRay( ri.geometric.rast, ray, cthis, rs, 0, ri.pRadianceMap, ior_stack ) ) {
				// Blend
				result.r = static_cast<float>(cthis[0]*sc.out.t.r + result.r);
				result.g = static_cast<float>(cthis[1]*sc.out.t.g + result.g);
				result.b = static_cast<float>(cthis[2]*sc.out.t.b + result.b);
			}			
		}

		c = RISE::RISEPel( result.r, result.g, result.b );	

		sc.pRayCaster = 0;
	}
}
Пример #8
0
void FloatLimitControlDlg::Invalidate()
{
	mValid = FALSE;
	Rect rect(IPoint2(0, 0), IPoint2(10, 10));
	InvalidateRect(mHWnd, &rect, FALSE);
}
Пример #9
0
// Screen coordinate beeing rendered
IPoint2 SContext::ScreenCoord(void)
{
	return IPoint2(0,0);
}