I try to create game options but got problem with cell size adjustment.For option "First move" I use names of users. I want to increase cell if name is too long. Or decrease font size if it easier.
Style for cells:
mCellStyle = new GUIStyle();//style for cells
mCellStyle.normal.background = Resources.Load<Texture2D>("Textures/button_up_9patch");
mCellStyle.onNormal.background = Resources.Load<Texture2D>("Textures/button_down_9patch");
mCellStyle.focused.background = mButtonStyle.active.background;
mCellStyle.fontSize = GUIUtils.GetKegel() - GUIUtils.GetKegel() / 5;
mCellStyle.border = new RectOffset(7, 7, 7, 7);
mCellStyle.padding = new RectOffset(20, 20, 20, 20);
mCellStyle.alignment = TextAnchor.MiddleCenter;
mCellStyle.wordWrap = true;
My code:
GUIStyle lBackStyle = new GUIStyle(mCellStyle);
lBackStyle.fontSize = GUIUtils.GetKegel();
lBackStyle.active.background = null;
lBackStyle.focused.background = null;
GUIStyle lStyle = new GUIStyle(lBackStyle);
lStyle.normal.background = null;
//create contents and calculate height
GUIContent lContent1 = new GUIContent(LanguageManager.GetText("FirstMove"));
float lElemH1 = lStyle.CalcHeight(lContent1, lMaxWidht);
GUIContent[] lArrayContent2 = new GUIContent[] { new GUIContent(MainScript.Logic.UserName), new GUIContent(MainScript.Logic.NurslingName) };
float lElemH2 = mCellStyle.CalcHeight(lArrayContent2[0], lMaxWidht);
GUIContent lContent3 = new GUIContent(LanguageManager.GetText("Difficulty"));
float lElemH3 = lStyle.CalcHeight(lContent3, lMaxWidht);
GUIContent[] lArrayContent4 = new GUIContent[] { new GUIContent(LanguageManager.GetText("Easy")), new GUIContent(LanguageManager.GetText("Hard")) };
float lElemH4 = mCellStyle.CalcHeight(lArrayContent4[0], lMaxWidht);
float lTotalH = lElemH1 + lElemH2 + lElemH3 /*+ 100*/;//reserve 100 for paddings
GUILayout.BeginArea(mAreaRect);
GUILayout.BeginVertical(lBackStyle, GUILayout.Height(lTotalH));
GUILayout.Label(lContent1, lStyle);
GamePreferences.setAIMakesFirstMove(GUILayout.SelectionGrid(GamePreferences.getAIMakesFirstMove(), lArrayContent2, 2, mCellStyle));
GUILayout.Label(lContent3, lStyle);
GamePreferences.setDifficulty(GUILayout.SelectionGrid(GamePreferences.getDifficulty(), lArrayContent4, 2, mCellStyle));
GUILayout.EndVertical();
GUILayout.EndArea();
ADDED: I just want to set height of cell in Selection Grid. Is it possible?
Ok, I found that I can pass GUILayoutOption as last parameter to set the height of cells:
GUILayout.SelectionGrid(GamePreferences.getFirstMove(), lArrayContent2, 2, mCellStyle, GUILayout.Height(lCellHeight))
But I still have no idea how I can fit cell size to it content.
float lElemH2 = mCellStyle.CalcHeight(lArrayContent2[0], lMaxWidht);
mCellStyle.CalcHeight ignores lenght of content and in lElemH2 I got height for single line text.
EDITED:
My fault, I sent wrong parameters to CalcHeight. Correct version:
float lElemH2 = mCellStyle.CalcHeight(lArrayContent2[0], lMaxWidht / cellsCount);
A chart on a form I created has two overlapping areas. The overlapping part works just fine. The problem is that visible graph only takes up half the height of the chart control:
The bottom half of the control is left empty (presumably because that's where the second area would have gone were the two areas not aligned?). I can't figure out how to get the chart to use the entire control. The code is below:
chart1.Dock = DockStyle.Fill;
chart1.Legends.Add(new Legend { Name = "Legend1" });
chart1.Location = new Point(435, 3);
chart1.Name = "chart1";
chart1.Size = new Size(426, 287);
chart1.TabIndex = 2;
chart1.Text = "chart1";
var firstArea = chart1.ChartAreas.Add("First Area");
var seriesFirst = chart1.Series.Add("First Series");
seriesFirst.ChartType = SeriesChartType.Line;
seriesFirst.Points.Add(new DataPoint(10, 55));
seriesFirst.Points.Add(new DataPoint(11, 56));
seriesFirst.Points.Add(new DataPoint(12, 59));
var secondArea = chart1.ChartAreas.Add("Second Area");
secondArea.BackColor = Color.Transparent;
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All;
secondArea.AlignmentStyle = AreaAlignmentStyles.All;
secondArea.AlignWithChartArea = firstArea.Name;
secondArea.AxisY.LabelStyle.Enabled = false;
secondArea.AxisX.LabelStyle.Enabled = false;
var seriesSecond = chart1.Series.Add("Second Series");
seriesSecond.ChartType = SeriesChartType.Line;
seriesSecond.ChartArea = secondArea.Name;
seriesSecond.Points.Add(new DataPoint(10, 1001));
seriesSecond.Points.Add(new DataPoint(11, 1015));
seriesSecond.Points.Add(new DataPoint(12, 1016));
This is some old code I've dug out and modified to suit your example. The problem is the InnerPlotPosition.Auto and Position.Auto status of the ChartAreas, thats why after you add the second chart the first charts auto position jumps up and then the second chart aligns with the new InnerPlotPosition.Auto values.
You can try turning this off but I think its easier to just position the first chart manually and then allow the second to align with the new manual position. It produces the below image (minus your legend you can work the values needed yourself)
Bit of pain in the ass solution but hopefully it helps
Dim chart1 As New Chart
Me.Controls.Add(chart1)
chart1.Location = New Point(435, 3)
chart1.Name = "chart1"
chart1.Size = New Size(426, 287)
chart1.TabIndex = 2
chart1.Text = "chart1"
Dim firstArea As ChartArea = chart1.ChartAreas.Add("First Area")
Dim seriesFirst = chart1.Series.Add("First Series")
seriesFirst.ChartType = SeriesChartType.Line
seriesFirst.Points.Add(New DataPoint(10, 55))
seriesFirst.Points.Add(New DataPoint(11, 56))
seriesFirst.Points.Add(New DataPoint(12, 59))
Dim secondArea As ChartArea = chart1.ChartAreas.Add("Second Area")
secondArea.BackColor = Color.Transparent
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All
secondArea.AlignmentStyle = AreaAlignmentStyles.All
secondArea.AlignWithChartArea = firstArea.Name
secondArea.AxisY.LabelStyle.Enabled = False
secondArea.AxisX.LabelStyle.Enabled = False
Dim seriesSecond = chart1.Series.Add("Second Series")
seriesSecond.ChartType = SeriesChartType.Line
seriesSecond.ChartArea = secondArea.Name
seriesSecond.Points.Add(New DataPoint(10, 1001))
seriesSecond.Points.Add(New DataPoint(11, 1015))
seriesSecond.Points.Add(New DataPoint(12, 1016))
' *** Set locational values here for your first chart***
Dim heightAboveChartArea As Integer = 20
Dim heightBelowChartArea As Integer = 20
Dim axisLabelHeight As Integer = 40
Dim widthLeftOfChartArea As Integer = 20
Dim widthRightOfChartArea As Integer = 20
Dim heightPerBar As Integer = 20
Dim numberOfPoints As Integer = chart1.Series(0).Points.Count
' *** The following code should not normally be modified ***
chart1.Height = heightAboveChartArea + heightBelowChartArea + axisLabelHeight + (numberOfPoints * heightPerBar)
chart1.ChartAreas(0).Position.X = widthLeftOfChartArea / chart1.Width * 100
chart1.ChartAreas(0).Position.Width = 100 - (widthRightOfChartArea / chart1.Width * 100) - chart1.ChartAreas(0).Position.X
chart1.ChartAreas(0).Position.Y = (heightAboveChartArea / chart1.Height * 100)
chart1.ChartAreas(0).Position.Height = 100 - (heightBelowChartArea / chart1.Height * 100) - chart1.ChartAreas(0).Position.Y
I thought about monkeying with the position, but I'd have to take into account borders and the legend and other chart components and assumed I'd never get it as good as the auto-positioning provided by the chart - and it would drive me nuts. However, the suggestion by TylerDurden led me to the idea of simply delaying the addition of the second series/area until after the chart had rendered at least once and had calculated the position. This turned out to be non-trivial, since for most of the chart's initialization the X, Y, Height and Width are still zero. The best way I found was to add the second series in the Form's Shown event:
private void OnShown(object sender, EventArgs eventArgs)
{
Application.DoEvents();
var f = chart1.ChartAreas[0].Position.ToRectangleF();
chart1.ChartAreas[0].Position.Auto = false;
chart1.ChartAreas[0].Position.X = f.X;
chart1.ChartAreas[0].Position.Y = f.Y;
chart1.ChartAreas[0].Position.Height = f.Height;
chart1.ChartAreas[0].Position.Width = f.Width;
// add second area/series here
The call to Application.DoEvents() is required to force the chart to render and calculate the Position. Since Position is a percentage, both chart areas will always occupy the full height and width of the parent Chart.
I have some problems with basic drag and drop scrolling algorithm. Here is my algorithm:
When mouse pressed down i set boolean dragging = true and store the current mouse x and y position in stored_position variable.
When mouse up i set boolean dragging = false.
On each frame i check dragging == true and if it is i calculate the dx = current_mouse.x - stored_position.x and dy = current_mouse.x - stored_position.y. Then i store current mouse position as the new stored_position and scroll my view (it is 2d camera object) by this dx dy, as the Camera.x -= dx, Camera.y -= dy (i need the inversion one because of camera specific).
The problem with this algorithm is that when i drag the camera it starting to blink and move around/shake. I think it is because when i move my mouse from left to right it traces dx like this:
71
-67
69
-68
69
-68
8
-5
So i think it is the mouse twitching(i mean the mouse is jumps back sometimes when we try to draw a line). Any idea of changing algorithm, maybe i miss something?
Here is example of this problem: https://dl.dropbox.com/u/78904724/as_host/buld_build_other.rar (you need to run the index.html chose the level and try to drag the screen).
Updated
Here is the example full source link (this is the random picture, i swear): https://dl.dropbox.com/u/78904724/as_host/scroll_test.rar
And this is the code i used (in example i use native flash events instead of using axgl checks to not confuse someone, i have both examples and it cause the same problems):
//variables with comments
private var dragging:Boolean = false; //dragging flag
private var current_mouse:Array; //stored mouse position array [0] - x, [1] - y
private var d:Array; //dx dy array [0] - x, [1] - y
[Embed(source = "test.jpg")] public static const _sprite:Class; //sprite graphics
private var view_sprite:AxSprite; //some image on the stage to drag it
//this is the class constructor code
view_sprite = new AxSprite(0, 0, _sprite);
add(view_sprite);
current_mouse = new Array();
d = new Array();
Ax.stage2D.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
current_mouse[0] = Ax.mouse.x;
current_mouse[1] = Ax.mouse.y;
dragging = true;
});
Ax.stage2D.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void {
dragging = false;
});
Ax.stage2D.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void {
if (dragging) {
d[0] = Ax.mouse.x - current_mouse[0];
d[1] = Ax.mouse.y - current_mouse[1];
Ax.camera.x -= d[0];
Ax.camera.y -= d[1];
current_mouse[0] = Ax.mouse.x;
current_mouse[1] = Ax.mouse.y;
}
});
I am totally confused but the problem was this two strings(thanks the axgl author for helping me):
current_mouse[0] = Ax.mouse.x;
current_mouse[1] = Ax.mouse.y;
And when i remove them the dragging will work perfectly. But... I swear i tried this before and nothing gonna happed, camera just started to move faster without this and now... it works!
Thank you all for trying to help my. If someone would have the similar problems here is the full worked source: https://dl.dropbox.com/u/78904724/as_host/scroll_test_worked.rar
And this is the thread on axgl.org: http://axgl.org/forums/viewtopic.php?f=12&p=394
I made a graph using MSChart and I was able to implement the zooming ability.
The graph can zoom but the problem arises when I want to move around after I zoom. When I click up and down on the y axis scrollbar, the scrolling increment is fine. However, for the x axis scrollbar, the scrolling increment is horrible. It will always go the very end even though there is data in the middle.
I tried looking online for the solution but was out of luck
here is my code:
// Chart area (where the axes and series are plotted)
ChartArea chartArea = new ChartArea();
chartArea.AxisX.Minimum = DateTime.MinValue.ToOADate();
chartArea.AxisY.Minimum = 0;
chartArea.AxisY.Maximum = 100;
//chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount;
chartArea.AxisX.Title = "Time";
chartArea.AxisX.LabelStyle.Format = DEFAULT_TIME_FORMAT_STRING;
chartArea.AxisY.LabelStyle.Format = "#########################";
chartArea.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
chartArea.BackColor = Color.Transparent;
m_chart.ChartAreas.Add(chartArea);
//add zoom-in features for x and y axis
m_chart.ChartAreas[0].CursorY.Interval = 0;
m_chart.ChartAreas[0].CursorY.IsUserEnabled = true;
m_chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
m_chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
m_chart.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true;
m_chart.ChartAreas[0].CursorX.Interval = 0;
//m_chart.ChartAreas[0].CursorX.AutoScroll = true;
//m_chart.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
m_chart.ChartAreas[0].CursorX.IsUserEnabled = true;
m_chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
m_chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
m_chart.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
I dont see what I am doing wrong
Set the scaleview type to the appropriate time selection.
m_chart.ChartAreas[0].AxisX.ScaleView.SizeType = "Seconds";
m_chart.ChartAreas[0].AxisX.ScaleView.MinSizeType= "Seconds";
m_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType= "Seconds";
m_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType= "Seconds";
Just change
m_chart.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = false;
then the scroll bar will comes outside the chartarea and you will not face that problem.
I need to import a mesh animation from Cinema4D into Blender.
I tried to do that using Collada.The Collada 1.3 importer doesn't seem to
do anything, the Collada 1.4 importer seems to work, but the animation didn't get
imported into Blender.
After reading this post:
Problem solved!
In case anyone comes in here looking
for the answer, I spoke to Otomo via
email and he kindly explained that the
problem lies in the .dae file being
exported incorrectly from C4D.
I hope Otomo doesn't mind me quoting
his email, I just don't want other
people to waste the time I did on such
a stupid problem.
Open up the .dae in a text editor and
change:
data
data
to this:
data
data
The fps must also be the same in both
c4d and blender.
I tried that, but I get an error:
FEEDBACK: Illusoft Collada 1.4 Plugin v0.3.162 started
The minor version of the file you are using is newer then the plug-in, so errors may occur.
image not found: None
Traceback (most recent call last):
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/cstartup.py", line 681, in ButtonEvent
onlyMainScene, applyModifiers)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 120, in __init__
self.__Import(fileName)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 127, in __Import
documentTranslator.Import(fileName)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 333, in Import
self.sceneGraph.LoadFromCollada(self.colladaDocument.visualScenesLibrary.items, self.colladaDocument.scene)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 550, in LoadFromCollada
ob = sceneNode.ObjectFromDae(daeNode)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 2079, in ObjectFromDae
a.LoadFromDae(daeAnimation, daeNode, newObject)
File "/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpymodules/colladaImEx/translator.py", line 1254, in LoadFromDae
interpolationsSource = daeAnimation.GetSource(interpolations.source)
AttributeError: 'NoneType' object has no attribute 'source'
Has anyone come across this issue ? Where can I find a newer Collada importer ?
Any hints on modifying the importer ?
Note:
Blender 2.5a2 imports collada animations, but the coordinate system is different and not all animation makes it through. For example, when I animate a box from 0,0,0 to 100,100,100,
rotate it on x,y,z and scale it on x,y,z, in Blender I get: translation on 1 axis(x which originally is y in cinema 4d), rotation is fine, scale is ignored.
I ended up writing a script.
I barely found usable C.O.F.F.E.E. documentation so went ahead and installed py4D.
The documentation is pretty good and the support on the forum is amazing.
Here's the current script:
import c4d
from c4d import documents,UVWTag
from c4d.utils import Deg
from c4d import symbols as sy, plugins, utils, bitmaps, gui
import math
def BlenderExport():
if not op: return
if op.GetType() != 5100:
print 'Selected Object is not an editable mesh'
return
unit = 0.001#for scale
foffset = 1#for frames
bd = doc.GetRenderBaseDraw()
scr = bd.GetFrameScreen()
rd = doc.GetActiveRenderData()
sizeX = int(rd[sy.RDATA_XRES_VIRTUAL])
sizeY = int(rd[sy.RDATA_YRES_VIRTUAL])
name = op.GetName()
fps = doc.GetFps()
sFrame= doc.GetMinTime().GetFrame(fps)
eFrame= doc.GetMaxTime().GetFrame(fps)
code = 'import Blender\nfrom Blender import *\nimport bpy\nfrom Blender.Mathutils import *\n\nscn = bpy.data.scenes.active\ncontext=scn.getRenderingContext()\ncontext.fps = '+str(fps)+'\ncontext.sFrame = '+str(sFrame)+'\ncontext.eFrame = '+str(eFrame)+'\ncontext.sizeX = '+str(sizeX)+'\ncontext.sizeY = ' + str(sizeY) + '\n'
def GetMesh(code):
# goto 0
doc.SetTime(c4d.BaseTime(0, fps))
c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK )
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
doc.SetTime(doc.GetTime())
c4d.EventAdd(c4d.EVENT_ANIMATE)
code += 'editmode = Window.EditMode()\nif editmode:\tWindow.EditMode(0)\n'
coords4D = op.GetPointAll()
coords = 'coords = ['
uvw = 0
uvs = 'uvs = ['
for tag in op.GetTags():
if tag.GetName() == "UVW":
uvw = tag
for c in coords4D:
coords += '['+str(c.x*unit)+','+str(c.z*unit)+','+str(c.y*unit)+'],'
coords = coords.rpartition(',')[0] + ']\n'
faces4D = op.GetAllPolygons()
fcount = 0
faces = 'faces = ['
for f in faces4D:
faces += '['+str(f)+'],'
uv = uvw.Get(fcount);
uvs += '[Vector('+str(uv[0].x)+','+str(1.0-uv[0].y)+'),Vector('+str(uv[1].x)+','+str(1.0-uv[1].y)+'),Vector('+str(uv[2].x)+','+str(1.0-uv[2].y)+')],'
fcount += 1
faces = faces.rpartition(',')[0] + ']\n'
uvs = uvs.rpartition(',')[0] + ']\n'
code = code + coords + faces + uvs
code += "c4dmesh = bpy.data.meshes.new('"+name+"_mesh')\nc4dmesh.verts.extend(coords)\nc4dmesh.faces.extend(faces)\n\nob = scn.objects.new(c4dmesh,'"+name+"_obj')\nc4dmesh.flipNormals()\n\nif editmode:\tWindow.EditMode(1)\n\n"
code += "c4dmesh.quadToTriangle()\nc4dmesh.addUVLayer('c4duv')\n"
code += "for f in range(0,"+str(fcount)+"):\n\tc4dmesh.faces[f].uv = uvs[f]\n"
return code
def GetIPOKeys(code):
# store properties for tracks
tracks = op.GetCTracks()
# 0,1,2 = Position, 3,4,5 = Scale, 6,7,8 = Rotation, 9 = PLA
# props = [[lx,f],[ly,f],[lz,f],[sx,f],[sy,f],[sz,f],[rx,f],[ry,f],[rz,f]]
try:
props = []
trackIDs = [3,4,5,6,7,8,0,2,1]
propVals = ['LocX','LocZ','LocY','SizeX','SizeY','SizeZ','RotZ','RotX','RotY']
propIPOs = ['Ipo.OB_LOCX','Ipo.OB_LOCZ','Ipo.OB_LOCY','Ipo.OB_SCALEX','Ipo.OB_SCALEY','Ipo.OB_SCALEY','Ipo.OB_ROTZ','Ipo.OB_ROTX','Ipo.OB_ROTY']
for t in range(0,9):
props.append([[],[]])
curve = tracks[t].GetCurve()
keyCount = curve.GetKeyCount()
for k in range(0,keyCount):
key = curve.GetKey(k)
props[t][0].append(key.GetValue())
props[t][1].append(key.GetTime().GetFrame(fps))
# find the max key
maxProp = max(enumerate(props), key = lambda tup: len(tup[1]))[1][1]
maxKeys = len(maxProp)
# loop through tracks and keys
for key in range(0,maxKeys):
code += "Blender.Set('curframe',"+str(maxProp[key])+")\n"
for track in trackIDs:
if(key < len(props[track][0])):
code += "ob."+propVals[track] + " = " + str(props[track][0][key]) + '\n'
code += 'key = ob.insertIpoKey(' + propIPOs[track] + ')\n'
except:
pass
return code
# mesh/morph animation -> mesh always has the same number of verts
def GetShapeKeys(code):
track = 0;
tracks = op.GetCTracks()
for t in tracks:
if(t.GetName() == 'PLA'): track = t
# track = op.GetCTracks()[9]
if track != 0:
curve = track.GetCurve()
keyCount = curve.GetKeyCount()
verts = []
frames = []
vertsNum = op.GetPointCount()
ctime = doc.GetTime()
for k in range(1,keyCount):
key = curve.GetKey(k)
frames.append(key.GetTime().GetFrame(fps))
c4d.StatusSetBar(100*(k/keyCount))
doc.SetTime(key.GetTime())
c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK )
c4dvecs = op.GetPointAll();
blendvecs = []
for v in c4dvecs:
blendvecs.append([v.x*unit,v.z*unit,v.y*unit])
verts.append(blendvecs)
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
doc.SetTime(ctime)
c4d.EventAdd(c4d.EVENT_ANIMATE)
c4d.StatusClear()
code += '\n\n# shape keys\nverts = ' + str(verts) + '\n'
code += "if(ob.activeShape == 0):\n\tob.insertShapeKey()\n\n"
for f in range(0,len(frames)):
kNum = str(f+1)
code += "if editmode: Window.EditMode(0)\n"
code += "for v in range(0,"+str(vertsNum)+"):\n\tc4dmesh.verts[v].co.x = verts["+str(f)+"][v][0]\n\tc4dmesh.verts[v].co.y = verts["+str(f)+"][v][1]\n\tc4dmesh.verts[v].co.z = verts["+str(f)+"][v][2]\n"
code += "c4dmesh.calcNormals()\n"
code += "ob.insertShapeKey()\n"
code += "if editmode: Window.EditMode(1)\n"
code += "shapeKey = ob.getData().getKey()\n"
code += "newIpo = Ipo.New('Key','newIpo')\n"
code += "if(shapeKey.ipo == None): shapeKey.ipo = newIpo\n"
code += "if(shapeKey.ipo['Key "+kNum+"'] == None): shapeKey.ipo.addCurve('Key "+kNum+"')\n"
if(f == 0): code += "shapeKey.ipo['Key "+kNum+"'].append(BezTriple.New(1.0,0.0,0.0))\n"
if(f > 0): code += "shapeKey.ipo['Key "+kNum+"'].append(BezTriple.New("+str(float(frames[f-1]))+",0.0,0.0))\n"
code += "shapeKey.ipo['Key "+kNum+"'].append(BezTriple.New("+str(float(frames[f]))+",1.0,0.0))\n"
else:
#no PLA tracks, look for morph tag
vertsNum = op.GetPointCount()
for tag in op.GetTags():
if tag.GetType() == 1019633:
# print tag[sy.MORPHTAG_MORPHS]
'''
work around
1. store first key for each track curve
2. set the first key value to 1 for the 1st track and 0 for the others
3. store the mesh vertices -> track name verts = []
4. after all track verts are stored, restore the original values
5. write the the curve keys for blender shape keys
'''
code += "if(ob.activeShape == 0):\n\tob.insertShapeKey()\n\n"
tc = 0
tcs = str(tc+1)
for track in tag.GetCTracks():
curve = track.GetCurve()
value = curve.GetKey(0).GetValue()
curve.GetKey(0).SetValue(curve,1.0)
print track.GetName()
doc.SetTime(c4d.BaseTime(0, fps))
c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK )
c4dvecs = op.GetPointAll();
blendverts = []
for v in c4dvecs:
blendverts.append([v.x*unit,v.z*unit,v.y*unit])
code += "Key"+tcs+"verts = " + str(blendverts)+"\n"
code += "if editmode: Window.EditMode(0)\n"
code += "for v in range(0,"+str(vertsNum)+"):\n\tc4dmesh.verts[v].co.x = Key"+tcs+"verts[v][0]\n\tc4dmesh.verts[v].co.y = Key"+tcs+"verts[v][1]\n\tc4dmesh.verts[v].co.z = Key"+tcs+"verts[v][2]\n"
code += "c4dmesh.calcNormals()\n"
code += "ob.insertShapeKey()\n"
code += "if editmode: Window.EditMode(1)\n"
code += "shapeKey = ob.getData().getKey()\n"
code += "newIpo = Ipo.New('Key','newIpo')\n"
code += "if(shapeKey.ipo == None): shapeKey.ipo = newIpo\n"
code += "if(shapeKey.ipo['Key "+tcs+"'] == None): shapeKey.ipo.addCurve('Key "+tcs+"')\n"
print op.GetPointAll()
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
curve.GetKey(0).SetValue(curve,value)
keyCount = curve.GetKeyCount()
for k in range(0,keyCount):
key = curve.GetKey(k)
value = key.GetValue()
frame = key.GetTime().GetFrame(fps)
code += "shapeKey.ipo['Key "+tcs+"'].append(BezTriple.New("+str(float(frame))+","+str(value)+",0.0))\n"
tc += 1
tcs = str(tc+1)
c4d.EventAdd(c4d.EVENT_ANIMATE)
return code
def GetCamera(code):
bd = doc.GetRenderBaseDraw()
cp = bd.GetSceneCamera(doc)
if cp is None: cp = bd.GetEditorCamera()
fov = Deg(cp[sy.CAMERAOBJECT_FOV])
pos = cp.GetPos()
rot = cp.GetRot()
code += "\nc4dCam = Camera.New('persp','c4d_"+cp.GetName()+"')\nc4dCam.drawPassepartout = True\nc4dCam.alpha = 0.5\nc4dCam.drawLimits = 1\nc4dCam.dofDist = 100.0\n"
code += "c4dCam.angle = "+str(fov)+"\nc4dCamLens = c4dCam.lens\nc4dCam.lens = c4dCamLens\nWindow.RedrawAll()\nc4dCamObj = scn.objects.new(c4dCam)\n"
code += "c4dCamObj.setLocation("+str([pos.x,pos.z,pos.y])+")\n"
code += "c4dCamObj.setEuler("+str([rot.x+(math.pi*.5),rot.y,rot.z])+")\n"
code += "scn.setCurrentCamera(c4dCamObj)\n"
return code
code = GetMesh(code)
code = GetIPOKeys(code)
code = GetShapeKeys(code)
code = GetCamera(code)
file = open(doc.GetDocumentPath()+'/'+op.GetName()+'_export.py','w')
file.write(code)
file.close()
BlenderExport()
It supports ipo keys(position,rotation,scale).
Point Level Animation gets converted to multiple shape keys.
Morph Tag animation preserves nicely.