The way to solve problems of this sort is to think about how much information you have, which is equivalent to how few possibilities remain.
Each weighing can have one of three possible outcomes: the left pan is heavier, ther right pan is heavier, or they weigh the same. You want each outcome to correspond to (roughly) the same number of remaining possibilities.
Initially, you have 26 or 27 possibilities: one item is heavier (and there are 13 choices for which that item that is), one item is lighter (out of 13), or maybe they're all the same. Since 27 = 3 * 3 * 3, you might hope that three weighings will suffice even if it's possible that they're all the same.
But for that to happen, the first weighing has to split the possibilities into three sets of exactly 9 each.
If on the first weighing you weigh 4 items against 4 others, the split is:
Left pan is heavier means one item in the left pan is heavier or one item in the right pan is lighter. That's 8 possibilities.
Right pan is heavier means one item in the left pan is lighter or one item in the right pan is heavier. Again 8 possibilities.
The pans balance. This must cover the 10 or 11 remaining possibilities. We cannot resolve these in only two more weighings. (Two weighings can have only 3 * 3 = 9 outcomes.)
So, four against four won't work. What about 5 against 5? This splits the 26 or 27 possibilities into sets of size 10, 10, and 6 or 7. Again, we cannot answer the question in only 2 more weighings.
More than 4 in each pan on the first weighing leaves too many possibilities for when the scales do not balance. Fewer than 5 leaves too many possibilities when they do balance.
The problem cannot be solved in only three weighings, even if you know there is an odd item. (Unless you know something else, like the color of the odd item, or that the odd item has a different density and there is some water we can immerse the apparatus in, or we can tie them together bolo-fashion, spin them, and observe how the center of mass moves. Or the scale has more than two pans.)
UPDATE: I just realized you only need to identify the odd item, not whether it's heavy or light. That means you start with only 13 possibilities. I'll be back.
I'M BACK...
Ignore the 13th item. In three weighings, you can tell if one of 12 items is odd, and if so whether it's light or heavy. I won't re-iterate this well-known solution. Re-interpret the "none of the 12 is odd" as "the so-far-ignored 13th item is odd".
You lose the ability to tell that there is an odd item, and if the odd item is the 13th you lose the ability to tell if it's light or heavy, but if you can assume there is an odd item you can always tell which it is, and sometimes (read usually) tell whether it's heavy or light.
Your solution can work as well as many others, like e.g.
6v6/0 -> 2v2/2-> 1v1/0
where XvY/Z
means weight X against Y, keep the heavier of them if any, Z otherwise.
Your solution has the merit to possibly require less weights in 2 cases out of 12, of course, although it can be improved a bit like this (I hope the notation for the arrow is self-explanatory):
3v3/6 -XY-> 1v1/1
-Z--> 2v2/2 -> 1v1/0
which requires only two weights in half of the cases.
Note that you can use up to 2 weights if you have no more than 9 marbles, because you can solve 9 marbles as follows:
3v3/3 -> 1v1/1
So, another perfectly valid solution to the 12 marbles puzzle might even be:
2v2/8 -XY-> 1v1/0
-Z--> 3v3/2 -XY-> 1v1/1
-Z--> 1v1/0
which requires only two weights in one third of the cases.
In general, if you have N weights at your disposal, you can solve the puzzle up to $3^N$ marbles included. With three weights, you can then have up to 27 marbles:
9v9/9 -> 3v3/3 -> 1v1/1
and it's basically the extension of a binary search with three alternatives instead: you can generally divide your lot into three partitions, and have a way forward by comparing only two of them.
Best Answer
If you can weigh $1,2,3,\ldots,40$, you can also automatically weigh $-1,-2,-3,\ldots,-40$ and trivially $0$. That is, you can determine $81=3^4$ different weights by putting each of the four weights into either of the pans or not use it. This means that the condition is "sharp" - any distinct distribution of pieces results in a distinct (integer) weight as difference between the two pans. If the pieces are $a\le b\le c\le d$, then the largest possible weights are $a+b+c+d=40$ (of course) and then $b+c+d$, which must be $39$, hence $a=1$. The next smallest weight is $b+c+d-a=38$, followed by $a+c+d$, which must be $37$, hence $b=3$. Then we already know that the sequence continues with $c+d=36$, $c+d-a=35$, $c+d-b+a=34$, $c+d-b=33$, $c+d-b-a=32$. Then the next smallest (i.e., the largest not having $+c$ and $+d$) is $a+b+d$ and must equal $31$, so that $c=9$ and finally $d=27$ (as we might have guessed meanwhile).