[Closed] Viewport with maxscript
hello everybody…
We are creating an interface using maxscript, we r almost done with the buttons and their functionalities, now we want to display the result of the scripts on a viewport built inside our interface independent of the main 3D MAX viewport, is that possible?
thanks in advance
Not really as far as I know… I once did a test by creating somekind of Direct3D ActiveX-Control (can’t remember which one exactly it was…), which could display some basic 3d stuff, but I don’t think this would count as a real solution since it was pretty limited and handling was horrible
But theoreticaly, it might be possible to create your own ActiveX-Control which can handle this stuff better, not sure how powerful ActiveX really is though…
The only thing I can think of is to export the scene as DWF and view the resulting file using the DWF viewer activex control which can be put in a maxscript dialog as well. Not a very nice solution but the only one I can think of right now.
- Martijn
hang on a second. are we sure we want a 3d model in the dialog? the original post didnt mention a 3d model if you want a render then you could render to a bitmap and just have a bitmap in the dialog.
solar_system2006 can you clarify exactly what you want to show in the viewport?
Of course it would also be possible to write a function that integrates with the max API that allows you to open an opengl viewport, which you could then call from maxscript
yes dave, an animated 3D MODELS
Thank you for ur replies guys!
I just found my old code, it uses a DirectAnimation ActiveX Control for the 3D view. But I don’t think that you can do anymore than viewing a simple object with this, and even this is difficult The object you want to display will be exported from max as a DirectX Object (so you need a .x exporter installed) and then gets loaded into the ActiveX Control. Also, the object should be positioned at the world origin and scale should be small.
Not sure if it is of any use at all, but maybe someone gets inspired
rollout ro_3DViewer "3D Viewer Test"
(
groupbox grp_3DView pos:[5,0] width:320 height:325
activeXControl ax_3DCtrl "DirectAnimation.DirectAnimationWindowedIntegratedMediaControl.1" pos:[15,15] width:300 height:300
button ui_LoadSelected "Load Selected Object" pos:[10,330] width:150
checkbutton ui_PlayRotation "Play Rotation" pos:[160,330] width:150 enabled:false
local objGeometry, meterLib, vLight, vCam
local isPlaying = false
local temp_obj_Name = "c:\\__tempObjExport.x"
function create3DViewport objFile =
(
--- initialize and fill viewport
meterLib = ax_3DCtrl.MeterLibrary
ax_3DCtrl.Image = meterLib.SolidColorImage meterLib.black
ax_3DCtrl.BackgroundImage = meterLib.SolidColorImage meterLib.black
ax_3DCtrl.updateInterval = 0.1
--- Create Camera
dim = 1000.1
vCam = (meterLib.PerspectiveCamera (10*dim) (0.1*dim)).Transform (meterLib.Translate3 0 0 0.01)
vCam = vCam.transform (meterLib.Rotate3Degrees (meterLib.YVector3) (10))
--- Create Light
vLight = meterLib.PointLight.Transform (meterLib.Translate3 (dim/2) (dim/4) (1.5*dim) )
--- Load Object
loadedObjGeometry = ( (meterLib.ImportGeometry (objFile)).DiffuseColor (meterLib.Red))
objGeometry = loadedObjGeometry.Transform (meterLib.Scale3 0.01 0.01 0.01)
--- Render View
finalImg = (meterLib.UnionGeometry (objGeometry) (vLight)).Render (vCam)
ax_3DCtrl.Image = finalImg
ax_3DCtrl.start()
)
on ui_PlayRotation changed state do
(
if state == true then
(
if isPlaying == false then ax_3DCtrl.stop()
--- give object constant rotationspeed
objGeometry = objGeometry.transform (meterLib.Rotate3RateDegrees (meterLib.XVector3) (20))
objGeometry = objGeometry.transform (meterLib.Rotate3RateDegrees (meterLib.YVector3) (20))
objGeometry = objGeometry.transform (meterLib.Rotate3RateDegrees (meterLib.ZVector3) (20))
--- render
finalImg = (meterLib.UnionGeometry (objGeometry) (vLight)).Render (vCam)
ax_3DCtrl.Image = finalImg
ax_3DCtrl.start()
isPlaying = true
)
if state == false then
(
ax_3DCtrl.pause()
ax_3DCtrl.stop()
)
)
on ui_LoadSelected pressed do
(
objs = getCurrentSelection()
if objs.count > 0 then
(
try ax_3DCtrl.stop()
catch()
exportfile temp_obj_Name #noprompt selectedOnly:true
create3DViewport temp_obj_Name
isPlaying = false
ui_PlayRotation.state = false
ui_PlayRotation.enabled = true
)
)
)
createDialog ro_3DViewer width:330 height:360
its a bit of a hack but maybe you could regester the dialog as a veiport and switch the layout to 2 panes 1, with the dialog in and one set to perspective. that was you can use all the existing max functionality with viewports to play back your animated 3d model.
Dave, I didnt understand your explanation much, could you elaborate more?
Cthulhu, I tried your method, I downloaded the panda tool script and tried to export an animated sphere with its path, but when I save( on the desktop for example) I dont find the file I just saved, any idea what is happening?