Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Creating 3D Objects at Run time


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Jul 28, 2017 5:33 PM Last Post By: Yilmaz Yoru Threads: [ Previous | Next ]
Barry Andrews

Posts: 71
Registered: 9/19/03
Creating 3D Objects at Run time  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2017 5:32 AM
I am using c++ Builder Tokyo to create a graphics scene using Rectangle3D and Text3D objects.
I am creating these at runtime as follows

		ColorMaterialSource         = new TColorMaterialSource(Owner);
		ColorMaterialSource->Parent = (TFmxObject *)Owner;;
		Text3D = new TText3D(Owner);
		Text3D->Name                = "Text3D_" + IntToStr(ObjectNumber++);
		Text3D->Parent              = (TFmxObject *)Owner;
		Text3D->Visible             = true;
		Text3D->Position->Z         = 0;
		Text3D->Font->Family        = "Arial";
		Text3D->MaterialSource      = ColorMaterialSource;
		Text3D->MaterialBackSource  = NULL;
		Text3D->MaterialShaftSource = NULL;
		Text3D->Projection          = TProjection::Screen;
		Text3D->WordWrap            = false;
		Text3D->Depth               = 0.01;
		Text3D->Projection          = TProjection::Screen;
		Text3D->Width               = Width;
		Text3D->Height              = Height;
		Text3D->Position->Y         = Y;
		Text3D->Position->X         = X;
		Text3D->Font->Size          = Height;
		Text3D->Font->Family        = Family;
		if (MaxLen && TheMsg.Length() > MaxLen)
		{
			TheMsg = TheMsg.SubString(0, MaxLen);
		}
		Text3D->Text                = TheMsg;
		Text3D->WordWrap            = false;
		Text3D->Depth               = 0.1;
		Text3D->HorzTextAlign       = Align;
		Text3D->Position->Z         = Zpos;
		Text3D->Visible             = Visible;

and
		TextureMaterialSource       = new TTextureMaterialSource(Owner);
		TextureMaterialSource->Parent = (TFmxObject *)Owner;;
		Rect3D = new TRectangle3D(Owner);
		Rect3D->Name                = "Rect3D_" + IntToStr(ObjectNumber++);
		Rect3D->Parent              = (TFmxObject *)Owner;
		Rect3D->Visible             = true;
		Rect3D->MaterialSource      = TextureMaterialSource;
		Rect3D->MaterialBackSource  = NULL;
		Rect3D->MaterialShaftSource = NULL;
		Rect3D->Projection          = TProjection::Screen;
		Rect3D->MaterialSource      = TextureMaterialSource;
		Rect3D->MaterialBackSource  = NULL;
		Rect3D->MaterialShaftSource = NULL;
		Rect3D->Projection          = TProjection::Screen;
		Rect3D->Height              = Height;
		Rect3D->Width               = Width;
		Rect3D->Depth               = 0.1;
		Rect3D->Position->Y         = Y;
		Rect3D->Position->X         = X;
		Rect3D->Position->Z         = Zpos;
		Rect3D->Visible             = Visible;


This works fine on 3 of my monitors, but when I use a USB to HDMI adapter, the graphics do not appear.
If I add a Rectangle3D at design time, this does appear.
The only difference I can see between the two is that the design time rectangle has
FRecalcOpacity set to false whereas the design time has this set to true, however I don't seem to be able to modify this.

Is there something I am doing wrong at runtime which is causing this to occur?
Yilmaz Yoru


Posts: 164
Registered: 1/1/03
Re: Creating 3D Objects at Run time  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 28, 2017 5:33 PM   in response to: Barry Andrews in response to: Barry Andrews
1. I don't know which version you have and which platform you run but as i remember Opacity parameter is being zero in some cases which makes it invisible.
Add Opacity to both of them. I always add Opacity and Visible parameters at the end of those 3D objects

Text3D->Opacity 			= 1.0;
Rect3D->Opacity 			=1.0;


2. Also your please check Owner and Parent parameters if they are wrong you cant see object in View3D. It should ve View3D or object in View3D.

3. And I see that you you use Width, Height variables, there are Owner's Width and Height. That means your object may be out of camera view
Use your specific variable like textWidth, textHeight etc.

4. Here is an example modified with your codes which uses camera projections, would you test this example with ViewPort and a Button. I don't think it is about screen and HDMI adapters. Probably it is about platform you run and version. Please test this simple example below , It should work on all platforms.


//---------------------------------------------------------------------------
 
#include <fmx.h>
#pragma hdrstop
 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
 
TColorMaterialSource  *ColorMaterialSource;
TTextureMaterialSource *TextureMaterialSource;
TText3D *Text3D;
TRectangle3D *Rect3D;
float X=0,Y=0,Z=0,H=4,W=40, D=1, fontH=1;
int numofText=0,numofRect=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 
		ColorMaterialSource         = new TColorMaterialSource(Viewport3D1);
		ColorMaterialSource->Parent = Viewport3D1;
		numofText++;
		Text3D = new TText3D(Owner);
		Text3D->Name                = "Text3D_"+IntToStr(numofText);
		Text3D->Parent              = Viewport3D1;
		Text3D->Font->Family        = "Arial";
		Text3D->MaterialSource      = ColorMaterialSource;
		Text3D->MaterialBackSource  = NULL;
		Text3D->MaterialShaftSource = NULL;
		Text3D->Projection          = TProjection::Camera;
		Text3D->WordWrap            = false;
		Text3D->Depth               = D;
		Text3D->Width               = W;
		Text3D->Height              = H;
		Text3D->Position->X         = X+Random(20);
		Text3D->Position->Y         = Y+Random(20);
		Text3D->Position->Z         = Z+Random(20);
		Text3D->Font->Size          = fontH;
		Text3D->Font->Family        = Text3D1->Font->Family; // Text3D1 added from IDE, or usetup your Family settings
 
 
		Text3D->Opacity 			= 1.0;
		Text3D->Visible             = true;
		Text3D->Text                = "TEST";
		Text3D->WordWrap            = false;
		Text3D->HorzTextAlign       = TTextAlign::Center;
 
		TextureMaterialSource       = new TTextureMaterialSource(Viewport3D1);
		TextureMaterialSource->Parent = Viewport3D1;
        numofRect++;
		Rect3D = new TRectangle3D(Viewport3D1);
		Rect3D->Name                = "Rect3D_"+IntToStr(numofRect);
		Rect3D->Parent              = Viewport3D1;
		Rect3D->Visible             = true;
		Rect3D->MaterialSource      = ColorMaterialSource; // or TextureMaterialSource 
		Rect3D->MaterialBackSource  = NULL;
		Rect3D->MaterialShaftSource = NULL;
		Rect3D->Projection          = TProjection::Camera;
		Rect3D->Height              = H;
		Rect3D->Width               = W;
		Rect3D->Depth               = D;
		Rect3D->Position->X         = X+Random(20);
		Rect3D->Position->Y         = Y+Random(20);
		Rect3D->Position->Z         = Z+Random(20);
 
		Rect3D->Opacity 			=1.0;
		Rect3D->Visible             = true;
 
}
//---------------------------------------------------------------------------
 


This example don't deletes objects creted by new() so at the end you should free all new objects. Something like with

TColorMaterialSource  *ColorMaterialSource[100];
TTextureMaterialSource *TextureMaterialSource[100];
TText3D *Text3D[100];
 


I recommend you linked lists or classes to store and delete all of them.

--
Best Regards
Dr. Yilmaz Yoru
Esenja Company
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02